mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
文件缓存增加高并发锁定支持
This commit is contained in:
10
library/think/cache/driver/File.php
vendored
10
library/think/cache/driver/File.php
vendored
@@ -109,8 +109,10 @@ class File extends Driver
|
|||||||
$content = file_get_contents($filename);
|
$content = file_get_contents($filename);
|
||||||
if (false !== $content) {
|
if (false !== $content) {
|
||||||
$expire = (int) substr($content, 8, 12);
|
$expire = (int) substr($content, 8, 12);
|
||||||
if (0 != $expire && $_SERVER['REQUEST_TIME'] > filemtime($filename) + $expire) {
|
if (0 != $expire && $_SERVER['REQUEST_TIME'] > filemtime($filename) + $expire && !is_file($filename . '.lock')) {
|
||||||
//缓存过期删除缓存文件
|
// 生成过期锁定文件
|
||||||
|
touch($filename . '.lock');
|
||||||
|
// 缓存过期删除缓存文件
|
||||||
$this->unlink($filename);
|
$this->unlink($filename);
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
@@ -152,6 +154,10 @@ class File extends Driver
|
|||||||
$result = file_put_contents($filename, $data);
|
$result = file_put_contents($filename, $data);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
isset($first) && $this->setTagItem($filename);
|
isset($first) && $this->setTagItem($filename);
|
||||||
|
if (is_file($filename . '.lock')) {
|
||||||
|
// 解除过期锁定文件
|
||||||
|
unlink($filename . '.lock');
|
||||||
|
}
|
||||||
clearstatcache();
|
clearstatcache();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user