]> source.dussan.org Git - nextcloud-server.git/commitdiff
Cache: Use getUserCache cache in OC_Cache
authorBart Visscher <bartv@thisnet.nl>
Mon, 25 Jun 2012 06:53:17 +0000 (08:53 +0200)
committerBart Visscher <bartv@thisnet.nl>
Mon, 25 Jun 2012 19:05:10 +0000 (21:05 +0200)
lib/cache.php

index 66d1049fb52c3ffbd909ccc5c8746ea3b2fd2b8f..e6f2beeb30620994cbbff880cce662c7a7c6141b 100644 (file)
@@ -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();
        }
 
 }