Added the Cache cleaning system.

This commit is contained in:
Teromene 2015-12-04 09:19:05 +00:00
parent a07839019e
commit f386fc4a10
2 changed files with 24 additions and 5 deletions

View file

@ -1,7 +1,6 @@
<?php <?php
/* /*
TODO : TODO :
- manage SSL detection because if library isn't loaded, some bridge crash !
- factorize the annotation system - factorize the annotation system
- factorize to adapter : Format, Bridge, Cache (actually code is almost the same) - factorize to adapter : Format, Bridge, Cache (actually code is almost the same)
- implement annotation cache for entrance page - implement annotation cache for entrance page
@ -17,6 +16,8 @@ date_default_timezone_set('UTC');
error_reporting(0); error_reporting(0);
//ini_set('display_errors','1'); error_reporting(E_ALL); // For debugging only. //ini_set('display_errors','1'); error_reporting(E_ALL); // For debugging only.
require_once __DIR__ . '/lib/RssBridge.php';
// extensions check // extensions check
if (!extension_loaded('openssl')) if (!extension_loaded('openssl'))
die('"openssl" extension not loaded. Please check "php.ini"'); die('"openssl" extension not loaded. Please check "php.ini"');
@ -24,8 +25,6 @@ if (!extension_loaded('openssl'))
// FIXME : beta test UA spoofing, please report any blacklisting by PHP-fopen-unfriendly websites // FIXME : beta test UA spoofing, please report any blacklisting by PHP-fopen-unfriendly websites
ini_set('user_agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20121202 Firefox/30.0 (rss-bridge/0.1; +https://github.com/sebsauvage/rss-bridge)'); ini_set('user_agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20121202 Firefox/30.0 (rss-bridge/0.1; +https://github.com/sebsauvage/rss-bridge)');
// -------
// default whitelist // default whitelist
$whitelist_file = './whitelist.txt'; $whitelist_file = './whitelist.txt';
$whitelist_default = array( $whitelist_default = array(
@ -59,9 +58,9 @@ else {
array_pop($whitelist_selection); array_pop($whitelist_selection);
} }
Cache::purge();
try{ try{
require_once __DIR__ . '/lib/RssBridge.php';
Bridge::setDir(__DIR__ . '/bridges/'); Bridge::setDir(__DIR__ . '/bridges/');
Format::setDir(__DIR__ . '/formats/'); Format::setDir(__DIR__ . '/formats/');

View file

@ -69,4 +69,24 @@ class Cache{
static public function isValidNameCache($nameCache){ static public function isValidNameCache($nameCache){
return preg_match('@^[A-Z][a-zA-Z0-9-]*$@', $nameCache); return preg_match('@^[A-Z][a-zA-Z0-9-]*$@', $nameCache);
} }
}
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() );
}
}
}
}
}