diff --git a/cachefile.php b/cachefile.php index 2dd07cf..66a6436 100644 --- a/cachefile.php +++ b/cachefile.php @@ -18,10 +18,25 @@ class cachefile throw new Exception ($e->getMessage(), $e->getCode()); } - $res = $this->read ("CACHE-Garbage"); + $fileCache = $this->directory."/".sha1 ("Garbage-Lock"); + $res = false; + if (file_exists ($fileCache)) + { + $datas = file_get_contents ($fileCache); + $datas = unserialize ($datas); + if (($datas["createTime"] + $datas["ttl"]) >= time ()) + { + $res = $datas["data"]; + } + } + if ($res === false) { - $this->write ("CACHE-Garbage", "Let's go, garbage !", 24*60*60); + $datas = array ("ttl"=>24*60*60, + "createTime"=>time(), + "data"=>"CACHE-Garbage"); + file_put_contents ($fileCache, serialize ($datas)); + chmod ($fileCache, 0666); $files = glob ($this->directory."/*", GLOB_NOSORT); foreach ($files as $fileCache) { @@ -40,7 +55,7 @@ class cachefile continue; } - if (($datas["createTime"] + $datas["ttl"]) >= time ()) + if (($datas["createTime"] + $datas["ttl"]) <= time ()) { unlink ($fileCache); } @@ -100,6 +115,7 @@ class cachefile throw new Exception ($e->getMessage(), $e->getCode()); } + $this->garbage (); $fileCache = $this->directory."/".sha1 ($id); touch ($fileCache.".lock"); $datas = array ("ttl"=>$ttl, @@ -127,6 +143,7 @@ class cachefile throw new Exception ($e->getMessage(), $e->getCode()); } + $this->garbage (); $fileCache = $this->directory."/".sha1 ($id); if (!file_exists ($fileCache)) return false;