# HG changeset patch # User Dan Fuhry # Date 1353342761 18000 # Node ID a52cac1b190d8414cb0104020dc94e2a062f4c34 # Parent 12c23b83c79d5518db19fd1bbea94b1fb6136971 Cacher: Add XCache support (partial) diff -r 12c23b83c79d -r a52cac1b190d includes/cache.php --- a/includes/cache.php Fri Dec 02 01:15:55 2011 -0500 +++ b/includes/cache.php Mon Nov 19 11:32:41 2012 -0500 @@ -21,6 +21,59 @@ class CacheManager { + public static function factory($backend = 'auto') + { + if ( function_exists('xcache_set') ) + return new CacheManager_XCache(); + else + return new CacheManager_File(); + } +} + +class CacheManager_XCache +{ + private $prefix; + + /** + * Constructor. Merely generates the prefix that will be prepended to cache objects. + */ + + public function __construct() + { + global $crypto_key; + $this->prefix = 'enano' . substr(md5($crypto_key), 0, 8) . '_'; + } + + /** + * @see CacheManager_File::fetch() + */ + + public function fetch($cache_id) + { + return xcache_isset($this->prefix . $cache_id) ? xcache_get($this->prefix . $cache_id) : false; + } + + /** + * @see CacheManager_File::store() + */ + + public function store($cache_id, $data, $ttl = 20) + { + return xcache_set($this->prefix . $cache_id, $data, $ttl * 60); + } + + /** + * @see CacheManager_File::purge() + */ + + public function purge($cache_id) + { + return xcache_unset($this->prefix . $cache_id); + } +} + +class CacheManager_File +{ /** * Fetch a cached piece of data. * @param string Cache ID. The timestamp is checked automatically. diff -r 12c23b83c79d -r a52cac1b190d includes/common.php --- a/includes/common.php Fri Dec 02 01:15:55 2011 -0500 +++ b/includes/common.php Mon Nov 19 11:32:41 2012 -0500 @@ -355,7 +355,7 @@ profiler_log('Ran checks'); // Init cache -$cache = new CacheManager(); +$cache = CacheManager::factory(); // Load plugin manager $plugins = new pluginLoader(); diff -r 12c23b83c79d -r a52cac1b190d includes/common_cli.php --- a/includes/common_cli.php Fri Dec 02 01:15:55 2011 -0500 +++ b/includes/common_cli.php Mon Nov 19 11:32:41 2012 -0500 @@ -125,7 +125,7 @@ profiler_log('Ran checks'); // Init cache -$cache = new CacheManager(); +$cache = CacheManager::factory(); // Load plugin manager $plugins = new pluginLoader();