cache.php: fs cache

This commit is contained in:
czaks 2015-04-05 17:13:55 +02:00
parent b78b3db010
commit 1d28b4be4d

View File

@ -50,6 +50,17 @@ class Cache {
case 'php': case 'php':
$data = isset(self::$cache[$key]) ? self::$cache[$key] : false; $data = isset(self::$cache[$key]) ? self::$cache[$key] : false;
break; break;
case 'fs':
$key = str_replace('/', '::', $key);
$key = str_replace("\0", '', $key);
if (!file_exists('tmp/cache/'.$key)) {
$data = false;
}
else {
$data = file_get_contents('tmp/cache/'.$key);
$data = json_decode($data, true);
}
break;
case 'redis': case 'redis':
if (!self::$cache) if (!self::$cache)
self::init(); self::init();
@ -87,6 +98,11 @@ class Cache {
case 'xcache': case 'xcache':
xcache_set($key, $value, $expires); xcache_set($key, $value, $expires);
break; break;
case 'fs':
$key = str_replace('/', '::', $key);
$key = str_replace("\0", '', $key);
file_put_contents('tmp/cache/'.$key, json_encode($value));
break;
case 'php': case 'php':
self::$cache[$key] = $value; self::$cache[$key] = $value;
break; break;
@ -113,6 +129,11 @@ class Cache {
case 'xcache': case 'xcache':
xcache_unset($key); xcache_unset($key);
break; break;
case 'fs':
$key = str_replace('/', '::', $key);
$key = str_replace("\0", '', $key);
unlink('tmp/cache/'.$key);
break;
case 'php': case 'php':
unset(self::$cache[$key]); unset(self::$cache[$key]);
break; break;
@ -134,6 +155,12 @@ class Cache {
case 'php': case 'php':
self::$cache = array(); self::$cache = array();
break; break;
case 'fs':
$files = glob('tmp/cache/*');
foreach ($files as $file) {
unlink($file);
}
break;
case 'redis': case 'redis':
if (!self::$cache) if (!self::$cache)
self::init(); self::init();