diff --git a/inc/cache.php b/inc/cache.php old mode 100644 new mode 100755 index 852aefa21..c5865fa9f --- a/inc/cache.php +++ b/inc/cache.php @@ -10,7 +10,7 @@ class Cache { private static $cache; public static function init() { global $config; - + switch ($config['cache']['enabled']) { case 'memcached': self::$cache = new Memcached(); @@ -31,9 +31,9 @@ public static function init() { } public static function get($key) { global $config, $debug; - + $key = $config['cache']['prefix'] . $key; - + $data = false; switch ($config['cache']['enabled']) { case 'memcached': @@ -67,20 +67,20 @@ public static function get($key) { $data = json_decode(self::$cache->get($key), true); break; } - + if ($config['debug']) $debug['cached'][] = $key . ($data === false ? ' (miss)' : ' (hit)'); - + return $data; } public static function set($key, $value, $expires = false) { global $config, $debug; - + $key = $config['cache']['prefix'] . $key; - + if (!$expires) $expires = $config['cache']['timeout']; - + switch ($config['cache']['enabled']) { case 'memcached': if (!self::$cache) @@ -107,15 +107,50 @@ public static function set($key, $value, $expires = false) { self::$cache[$key] = $value; break; } - + + if ($config['debug']) + $debug['cached'][] = $key . ' (set)'; + } + public static function store($key, $value) { + global $config, $debug; + + $key = $config['cache']['prefix'] . $key; + + switch ($config['cache']['enabled']) { + case 'memcached': + if (!self::$cache) + self::init(); + self::$cache->set($key, $value); + break; + case 'redis': + if (!self::$cache) + self::init(); + self::$cache->set($key, json_encode($value)); + break; + case 'apc': + apc_store($key, $value); + break; + case 'xcache': + xcache_set($key, $value); + break; + case 'fs': + $key = str_replace('/', '::', $key); + $key = str_replace("\0", '', $key); + file_put_contents('tmp/cache/'.$key, json_encode($value)); + break; + case 'php': + self::$cache[$key] = $value; + break; + } + if ($config['debug']) $debug['cached'][] = $key . ' (set)'; } public static function delete($key) { global $config, $debug; - + $key = $config['cache']['prefix'] . $key; - + switch ($config['cache']['enabled']) { case 'memcached': case 'redis': @@ -138,13 +173,13 @@ public static function delete($key) { unset(self::$cache[$key]); break; } - + if ($config['debug']) $debug['cached'][] = $key . ' (deleted)'; } public static function flush() { global $config; - + switch ($config['cache']['enabled']) { case 'memcached': if (!self::$cache) @@ -166,7 +201,7 @@ public static function flush() { self::init(); return self::$cache->flushDB(); } - + return false; } } diff --git a/inc/functions.php b/inc/functions.php index d7c86ae6e..051d22595 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -34,11 +34,11 @@ loadConfig(); function init_locale($locale, $error='error') { - if ($locale === 'en') + if ($locale === 'en') $locale = 'en_US.utf8'; if (extension_loaded('gettext')) { - setlocale(LC_ALL, $locale); + setlocale(LC_ALL, $locale); bindtextdomain('tinyboard', './inc/locale'); bind_textdomain_codeset('tinyboard', 'UTF-8'); textdomain('tinyboard'); @@ -67,7 +67,7 @@ function loadConfig() { } - if (isset($config['cache_config']) && + if (isset($config['cache_config']) && $config['cache_config'] && $config = Cache::get('config_' . $boardsuffix ) ) { $events = Cache::get('events_' . $boardsuffix ); @@ -87,7 +87,7 @@ function loadConfig() { $config = array(); // We will indent that later. - reset_events(); + reset_events(); $arrays = array( 'db', @@ -286,7 +286,7 @@ function loadConfig() { if ($config['recaptcha']) require_once 'inc/lib/recaptcha/recaptchalib.php'; - + if ($config['cache']['enabled']) require_once 'inc/cache.php'; @@ -311,7 +311,7 @@ function loadConfig() { Cache::set('config_'.$boardsuffix, $config); Cache::set('events_'.$boardsuffix, $events); } - + if ($config['debug']) { if (!isset($debug)) { $debug = array( @@ -351,7 +351,7 @@ function basic_error_function_because_the_other_isnt_loaded_yet($message, $prior '
This alternative error page is being displayed because the other couldn\'t be found or hasn\'t loaded yet.