diff --git a/caches/FileCache.php b/caches/FileCache.php index bffdff3..ce8394e 100644 --- a/caches/FileCache.php +++ b/caches/FileCache.php @@ -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()); } } diff --git a/index.php b/index.php index a20415d..599135a 100644 --- a/index.php +++ b/index.php @@ -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 diff --git a/lib/CacheInterface.php b/lib/CacheInterface.php index ab1066e..5753c0e 100644 --- a/lib/CacheInterface.php +++ b/lib/CacheInterface.php @@ -3,5 +3,5 @@ interface CacheInterface { public function loadData(); public function saveData($datas); public function getTime(); - public function purgeCache(); + public function purgeCache($duration); }