From 5c309e93dc82e3af8b465944961b48fc4f685759 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 8 Oct 2016 16:18:10 +0200 Subject: [PATCH] [cache] Specify cache duration for 'purgeCache' --- caches/FileCache.php | 5 ++--- index.php | 2 +- lib/CacheInterface.php | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/caches/FileCache.php b/caches/FileCache.php index bffdff3f..ce8394e2 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 a20415d8..599135a6 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 ab1066e3..5753c0eb 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); }