[cache] Specify cache duration for 'purgeCache'

This commit is contained in:
logmanoriginal 2016-10-08 16:18:10 +02:00
parent 2d56b717cf
commit 5c309e93dc
3 changed files with 4 additions and 5 deletions

View file

@ -31,8 +31,7 @@ class FileCache implements CacheInterface {
return false;
}
public function purgeCache(){
$cacheTimeLimit = time() - 86400; // 86400 -> 24h
public function purgeCache($duration){
$cachePath = $this->getPath();
if(file_exists($cachePath)){
$cacheIterator = new RecursiveIteratorIterator(
@ -44,7 +43,7 @@ class FileCache implements CacheInterface {
if(in_array($cacheFile->getBasename(), array('.', '..')))
continue;
elseif($cacheFile->isFile()){
if(filemtime($cacheFile->getPathname()) < $cacheTimeLimit)
if(filemtime($cacheFile->getPathname()) < time() - $duration)
unlink($cacheFile->getPathname());
}
}

View file

@ -131,7 +131,7 @@ try {
// Initialize cache
$cache = Cache::create('FileCache');
$cache->setPath(__DIR__ . '/cache');
$cache->purgeCache();
$cache->purgeCache(86400); // 24 hours
$cache->setParameters($params);
// Load cache & data

View file

@ -3,5 +3,5 @@ interface CacheInterface {
public function loadData();
public function saveData($datas);
public function getTime();
public function purgeCache();
public function purgeCache($duration);
}