From 4e4a1a4274940a9aa7b4c9313d13f8aeb80123ba Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 25 Jun 2012 08:53:17 +0200 Subject: [PATCH] Cache: Use getUserCache cache in OC_Cache --- lib/cache.php | 61 ++++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/lib/cache.php b/lib/cache.php index 66d1049fb52..e6f2beeb306 100644 --- a/lib/cache.php +++ b/lib/cache.php @@ -7,7 +7,7 @@ */ class OC_Cache { - static protected $cache; + static protected $user_cache; static protected $global_cache; static public function getGlobalCache() { @@ -18,61 +18,48 @@ class OC_Cache { } static public function getUserCache() { - if (!self::$cache) { - self::init(); - } - return self::$cache; - } - static protected function init() { - $fast_cache = null; - if (!$fast_cache && function_exists('xcache_set')) { - $fast_cache = new OC_Cache_XCache(); - } - if (!$fast_cache && function_exists('apc_store')) { - $fast_cache = new OC_Cache_APC(); - } - self::$cache = new OC_Cache_File(); - if ($fast_cache) { - self::$cache = new OC_Cache_Broker($fast_cache, self::$cache); + if (!self::$user_cache) { + $fast_cache = null; + if (!$fast_cache && function_exists('xcache_set')) { + $fast_cache = new OC_Cache_XCache(); + } + if (!$fast_cache && function_exists('apc_store')) { + $fast_cache = new OC_Cache_APC(); + } + self::$user_cache = new OC_Cache_File(); + if ($fast_cache) { + self::$user_cache = new OC_Cache_Broker($fast_cache, self::$user_cache); + } } + return self::$user_cache; } static public function get($key) { - if (!self::$cache) { - self::init(); - } - return self::$cache->get($key); + $user_cache = self::getUserCache(); + return $user_cache->get($key); } static public function set($key, $value, $ttl=0) { if (empty($key)) { return false; } - if (!self::$cache) { - self::init(); - } - return self::$cache->set($key, $value, $ttl); + $user_cache = self::getUserCache(); + return $user_cache->set($key, $value, $ttl); } static public function hasKey($key) { - if (!self::$cache) { - self::init(); - } - return self::$cache->hasKey($key); + $user_cache = self::getUserCache(); + return $user_cache->hasKey($key); } static public function remove($key) { - if (!self::$cache) { - self::init(); - } - return self::$cache->remove($key); + $user_cache = self::getUserCache(); + return $user_cache->remove($key); } static public function clear() { - if (!self::$cache) { - self::init(); - } - return self::$cache->clear(); + $user_cache = self::getUserCache(); + return $user_cache->clear(); } } -- 2.39.5