diff --git a/index.php b/index.php index a2546d68..8d28fa2b 100644 --- a/index.php +++ b/index.php @@ -1,7 +1,6 @@ >>>>>> a40bbbd2deb5f59d88d61fe2253a16c28deb900b // cache file purge - delete cache files older than 24 hours $cacheTimeLimit = time() - 60*60*24 ; @@ -77,9 +81,12 @@ else { array_pop($whitelist_selection); } +<<<<<<< HEAD +======= +Cache::purge(); +>>>>>>> a40bbbd2deb5f59d88d61fe2253a16c28deb900b try{ - require_once __DIR__ . '/lib/RssBridge.php'; Bridge::setDir(__DIR__ . '/bridges/'); Format::setDir(__DIR__ . '/formats/'); diff --git a/lib/Cache.php b/lib/Cache.php index 9bf8ffa8..fa80bc04 100644 --- a/lib/Cache.php +++ b/lib/Cache.php @@ -69,4 +69,24 @@ class Cache{ static public function isValidNameCache($nameCache){ return preg_match('@^[A-Z][a-zA-Z0-9-]*$@', $nameCache); } -} \ No newline at end of file + + static public function purge() { + $cacheTimeLimit = time() - 60*60*24 ; + $cachePath = 'cache'; + if(file_exists($cachePath)) { + $cacheIterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($cachePath), + RecursiveIteratorIterator::CHILD_FIRST + ); + foreach ($cacheIterator as $cacheFile) { + if (in_array($cacheFile->getBasename(), array('.', '..'))) + continue; + elseif ($cacheFile->isFile()) { + if( filemtime($cacheFile->getPathname()) < $cacheTimeLimit ) + unlink( $cacheFile->getPathname() ); + } + } + } + } + +}