cachefile : Run the garbage each 24h automatically
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1585 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user