From 9134d8a3e5f429ce326f368f2a846e5129bf0318 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 13 Jan 2018 22:09:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=B9=E8=BF=9Bfile=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E7=9A=84=E7=BC=93=E5=AD=98inc=E5=92=8Cdec=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=B8=8D=E6=94=B9=E5=8F=98=E7=BC=93=E5=AD=98=E6=9C=89=E6=95=88?= =?UTF-8?q?=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/driver/File.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/library/think/cache/driver/File.php b/library/think/cache/driver/File.php index cafa0c01..307c2fa1 100644 --- a/library/think/cache/driver/File.php +++ b/library/think/cache/driver/File.php @@ -170,11 +170,14 @@ class File extends Driver public function inc($name, $step = 1) { if ($this->has($name)) { - $value = $this->get($name) + $step; + $value = $this->get($name) + $step; + $expire = $this->expire; } else { - $value = $step; + $value = $step; + $expire = 0; } - return $this->set($name, $value, 0) ? $value : false; + + return $this->set($name, $value, $expire) ? $value : false; } /** @@ -187,11 +190,14 @@ class File extends Driver public function dec($name, $step = 1) { if ($this->has($name)) { - $value = $this->get($name) - $step; + $value = $this->get($name) - $step; + $expire = $this->expire; } else { - $value = -$step; + $value = -$step; + $expire = 0; } - return $this->set($name, $value, 0) ? $value : false; + + return $this->set($name, $value, $expire) ? $value : false; } /** From a44b5b489eb7a5556801d113f8863ba2aa41fe75 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 13 Jan 2018 22:39:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/driver/File.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/think/cache/driver/File.php b/library/think/cache/driver/File.php index 307c2fa1..a072f41f 100644 --- a/library/think/cache/driver/File.php +++ b/library/think/cache/driver/File.php @@ -27,6 +27,8 @@ class File extends Driver 'data_compress' => false, ]; + protected $expire; + /** * 构造函数 * @param array $options @@ -106,13 +108,15 @@ class File extends Driver if (!is_file($filename)) { return $default; } - $content = file_get_contents($filename); + $content = file_get_contents($filename); + $this->expire = null; if (false !== $content) { $expire = (int) substr($content, 8, 12); if (0 != $expire && time() > filemtime($filename) + $expire) { return $default; } - $content = substr($content, 32); + $this->expire = $expire; + $content = substr($content, 32); if ($this->options['data_compress'] && function_exists('gzcompress')) { //启用数据压缩 $content = gzuncompress($content);