From f637f06e0de99170b5156d7025226b520c84f24d Mon Sep 17 00:00:00 2001 From: "xiaobo.sun" <5ini99@sohu.com> Date: Sun, 14 Feb 2016 16:25:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=9A=84File=E7=BC=93=E5=AD=98=E6=97=B6=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加删除本地文件缓存时优先判断是否存在,如果存在则进行unlink删除操作 --- library/think/cache/driver/File.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/library/think/cache/driver/File.php b/library/think/cache/driver/File.php index 533a4634..68f38a0c 100644 --- a/library/think/cache/driver/File.php +++ b/library/think/cache/driver/File.php @@ -104,7 +104,7 @@ class File $expire = (int) substr($content, 8, 12); if (0 != $expire && time() > filemtime($filename) + $expire) { //缓存过期删除缓存文件 - unlink($filename); + $this->unlink($filename); return false; } $content = substr($content, 20, -3); @@ -157,7 +157,7 @@ class File // 出列 $key = array_shift($queue); // 删除缓存 - unlink($this->filename($key)); + $this->unlink($this->filename($key)); } file_put_contents($queue_file, serialize($queue)); } @@ -176,7 +176,7 @@ class File */ public function rm($name) { - return unlink($this->filename($name)); + return $this->unlink($this->filename($name)); } /** @@ -191,7 +191,7 @@ class File while ($file = readdir($dir)) { $check = is_dir($file); if (!$check) { - unlink($path . $file); + $this->unlink($path . $file); } } @@ -199,4 +199,16 @@ class File return true; } } + + /** + * 判断文件是否存在后,删除 + * @param $path + * @return bool + * @author byron sampson + * @return boolean + */ + private function unlink($path) + { + return is_file($path) && unlink($path); + } }