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; } /**