[cache] Specify cache duration for 'purgeCache'
This commit is contained in:
parent
2d56b717cf
commit
5c309e93dc
3 changed files with 4 additions and 5 deletions
|
@ -31,8 +31,7 @@ class FileCache implements CacheInterface {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function purgeCache(){
|
public function purgeCache($duration){
|
||||||
$cacheTimeLimit = time() - 86400; // 86400 -> 24h
|
|
||||||
$cachePath = $this->getPath();
|
$cachePath = $this->getPath();
|
||||||
if(file_exists($cachePath)){
|
if(file_exists($cachePath)){
|
||||||
$cacheIterator = new RecursiveIteratorIterator(
|
$cacheIterator = new RecursiveIteratorIterator(
|
||||||
|
@ -44,7 +43,7 @@ class FileCache implements CacheInterface {
|
||||||
if(in_array($cacheFile->getBasename(), array('.', '..')))
|
if(in_array($cacheFile->getBasename(), array('.', '..')))
|
||||||
continue;
|
continue;
|
||||||
elseif($cacheFile->isFile()){
|
elseif($cacheFile->isFile()){
|
||||||
if(filemtime($cacheFile->getPathname()) < $cacheTimeLimit)
|
if(filemtime($cacheFile->getPathname()) < time() - $duration)
|
||||||
unlink($cacheFile->getPathname());
|
unlink($cacheFile->getPathname());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ try {
|
||||||
// Initialize cache
|
// Initialize cache
|
||||||
$cache = Cache::create('FileCache');
|
$cache = Cache::create('FileCache');
|
||||||
$cache->setPath(__DIR__ . '/cache');
|
$cache->setPath(__DIR__ . '/cache');
|
||||||
$cache->purgeCache();
|
$cache->purgeCache(86400); // 24 hours
|
||||||
$cache->setParameters($params);
|
$cache->setParameters($params);
|
||||||
|
|
||||||
// Load cache & data
|
// Load cache & data
|
||||||
|
|
|
@ -3,5 +3,5 @@ interface CacheInterface {
|
||||||
public function loadData();
|
public function loadData();
|
||||||
public function saveData($datas);
|
public function saveData($datas);
|
||||||
public function getTime();
|
public function getTime();
|
||||||
public function purgeCache();
|
public function purgeCache($duration);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue