mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 23:52:49 +08:00
改进缓存驱动
This commit is contained in:
8
library/think/cache/Driver.php
vendored
8
library/think/cache/Driver.php
vendored
@@ -120,22 +120,22 @@ abstract class Driver
|
|||||||
public function remember($name, $value, $expire = null)
|
public function remember($name, $value, $expire = null)
|
||||||
{
|
{
|
||||||
if (!$this->has($name)) {
|
if (!$this->has($name)) {
|
||||||
while ($this->has($name . '.lock')) {
|
while ($this->has($name . '_lock')) {
|
||||||
// 存在锁定则等待
|
// 存在锁定则等待
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 锁定
|
// 锁定
|
||||||
$this->set($name . '.lock', true);
|
$this->set($name . '_lock', true);
|
||||||
if ($value instanceof \Closure) {
|
if ($value instanceof \Closure) {
|
||||||
$value = call_user_func($value);
|
$value = call_user_func($value);
|
||||||
}
|
}
|
||||||
$this->set($name, $value, $expire);
|
$this->set($name, $value, $expire);
|
||||||
// 解锁
|
// 解锁
|
||||||
$this->rm($name . '.lock');
|
$this->rm($name . '_lock');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// 解锁
|
// 解锁
|
||||||
$this->rm($name . '.lock');
|
$this->rm($name . '_lock');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$value = $this->get($name);
|
$value = $this->get($name);
|
||||||
|
|||||||
12
library/think/cache/driver/File.php
vendored
12
library/think/cache/driver/File.php
vendored
@@ -109,12 +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 && !is_file($filename . '.lock')) {
|
if (0 != $expire && $_SERVER['REQUEST_TIME'] > filemtime($filename) + $expire) {
|
||||||
// 生成过期锁定文件
|
|
||||||
touch($filename . '.lock');
|
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
$content = substr($content, 20, -3);
|
$content = substr($content, 32);
|
||||||
if ($this->options['data_compress'] && function_exists('gzcompress')) {
|
if ($this->options['data_compress'] && function_exists('gzcompress')) {
|
||||||
//启用数据压缩
|
//启用数据压缩
|
||||||
$content = gzuncompress($content);
|
$content = gzuncompress($content);
|
||||||
@@ -148,14 +146,10 @@ class File extends Driver
|
|||||||
//数据压缩
|
//数据压缩
|
||||||
$data = gzcompress($data, 3);
|
$data = gzcompress($data, 3);
|
||||||
}
|
}
|
||||||
$data = "<?php\n//" . sprintf('%012d', $expire) . $data . "\n?>";
|
$data = "<?php\n//" . sprintf('%012d', $expire) . "\n exit();?>\n" . $data;
|
||||||
$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