]> source.dussan.org Git - nextcloud-server.git/commitdiff
add option to only get fast cache
authorRobin Appelman <icewind@owncloud.com>
Sun, 22 Jul 2012 01:21:20 +0000 (03:21 +0200)
committerRobin Appelman <icewind@owncloud.com>
Sun, 22 Jul 2012 01:21:20 +0000 (03:21 +0200)
lib/cache.php

index 36f409ab71a5f2cb4bba1cf1f16a9130e731b372..55f189a5da8e1f5400c3a47cabc5ebf0900f31d3 100644 (file)
@@ -15,24 +15,40 @@ class OC_Cache {
         * @var OC_Cache $global_cache
         */
        static protected $global_cache;
+       /**
+        * @var OC_Cache $global_cache_fast
+        */
+       static protected $global_cache_fast;
+       /**
+        * @var OC_Cache $user_cache_fast
+        */
+       static protected $user_cache_fast;
        static protected $isFast=null;
 
        /**
         * get the global cache
         * @return OC_Cache
         */
-       static public function getGlobalCache() {
+       static public function getGlobalCache($fast=false) {
                if (!self::$global_cache) {
-                       $fast_cache = null;
-                       if (!$fast_cache && function_exists('xcache_set')) {
-                               $fast_cache = new OC_Cache_XCache(true);
+                       self::$global_cache_fast = null;
+                       if (!self::$global_cache_fast && function_exists('xcache_set')) {
+                               self::$global_cache_fast = new OC_Cache_XCache(true);
                        }
-                       if (!$fast_cache && function_exists('apc_store')) {
-                               $fast_cache = new OC_Cache_APC(true);
+                       if (!self::$global_cache_fast && function_exists('apc_store')) {
+                               self::$global_cache_fast = new OC_Cache_APC(true);
                        }
+                       
                        self::$global_cache = new OC_Cache_FileGlobal();
-                       if ($fast_cache) {
-                               self::$global_cache = new OC_Cache_Broker($fast_cache, self::$global_cache);
+                       if (self::$global_cache_fast) {
+                               self::$global_cache = new OC_Cache_Broker(self::$global_cache_fast, self::$global_cache);
+                       }
+               }
+               if($fast){
+                       if(self::$global_cache_fast){
+                               return self::$global_cache_fast;
+                       }else{
+                               return false;
                        }
                }
                return self::$global_cache;
@@ -42,18 +58,27 @@ class OC_Cache {
         * get the user cache
         * @return OC_Cache
         */
-       static public function getUserCache() {
+       static public function getUserCache($fast=false) {
                if (!self::$user_cache) {
-                       $fast_cache = null;
-                       if (!$fast_cache && function_exists('xcache_set')) {
-                               $fast_cache = new OC_Cache_XCache();
+                       self::$user_cache_fast = null;
+                       if (!self::$user_cache_fast && function_exists('xcache_set')) {
+                               self::$user_cache_fast = new OC_Cache_XCache();
                        }
-                       if (!$fast_cache && function_exists('apc_store')) {
-                               $fast_cache = new OC_Cache_APC();
+                       if (!self::$user_cache_fast && function_exists('apc_store')) {
+                               self::$user_cache_fast = 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);
+                       if (self::$user_cache_fast) {
+                               self::$user_cache = new OC_Cache_Broker(self::$user_cache_fast, self::$user_cache);
+                       }
+               }
+
+               if($fast){
+                       if(self::$user_cache_fast){
+                               return self::$user_cache_fast;
+                       }else{
+                               return false;
                        }
                }
                return self::$user_cache;