From 64bb1f4b23e6afdacf553392333fe6ba194ca5f3 Mon Sep 17 00:00:00 2001 From: huangdijia Date: Tue, 26 Jan 2016 13:56:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=9Fcache=E9=A9=B1=E5=8A=A8Simple=E6=94=B9?= =?UTF-8?q?=E5=90=8DLite=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=9C=89=E6=95=88?= =?UTF-8?q?=E6=9C=9F=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cache/driver/{Simple.php => Lite.php} | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) rename library/think/cache/driver/{Simple.php => Lite.php} (76%) diff --git a/library/think/cache/driver/Simple.php b/library/think/cache/driver/Lite.php similarity index 76% rename from library/think/cache/driver/Simple.php rename to library/think/cache/driver/Lite.php index b8219230..de910e5c 100644 --- a/library/think/cache/driver/Simple.php +++ b/library/think/cache/driver/Lite.php @@ -17,12 +17,13 @@ use think\Cache; * 文件类型缓存类 * @author liu21st */ -class Simple +class Lite { protected $options = [ 'prefix' => '', 'path' => '', + 'expire' => 0, // 等于 10*365*24*3600(10年) ]; /** @@ -64,6 +65,13 @@ class Simple Cache::$readTimes++; $filename = $this->filename($name); if (is_file($filename)) { + // 判断是否过期 + $mtime = filemtime($filename); + if ($mtimeoptions['expire']; + } + // 模拟永久 + if (0===$expire) { + $expire = 10*365*24*3600; + } $filename = $this->filename($name); // 缓存数据 + /* $dir = dirname($filename); // 目录不存在则创建 - //if (!is_dir($dir)) - // mkdir($dir,0755,true); - return file_put_contents($filename, ("")); + if (!is_dir($dir)) + mkdir($dir,0755,true); + */ + $ret = file_put_contents($filename, ("")); + // 通过设置修改时间实现有效期 + if ($ret) { + touch($filename, time()+$expire); + } + return $ret; } /**