]> source.dussan.org Git - nextcloud-server.git/commitdiff
add method to OC_Cache to check whether a fast cache (apc/xdebug/etc) is available
authorRobin Appelman <icewind@owncloud.com>
Sun, 22 Jul 2012 00:23:24 +0000 (02:23 +0200)
committerRobin Appelman <icewind@owncloud.com>
Sun, 22 Jul 2012 00:23:24 +0000 (02:23 +0200)
lib/cache.php

index 1f269174fad663cf6bb2b6ad3611379d7afee971..6f4b3e6e3f638d9616ef31216b78ee36cc8fc397 100644 (file)
@@ -7,9 +7,20 @@
  */
 
 class OC_Cache {
+       /**
+        * @var OC_Cache $user_cache
+        */
        static protected $user_cache;
+       /**
+        * @var OC_Cache $global_cache
+        */
        static protected $global_cache;
+       static protected $isFast=null;
 
+       /**
+        * get the global cache
+        * @return OC_Cache
+        */
        static public function getGlobalCache() {
                if (!self::$global_cache) {
                        $fast_cache = null;
@@ -27,6 +38,10 @@ class OC_Cache {
                return self::$global_cache;
        }
 
+       /**
+        * get the user cache
+        * @return OC_Cache
+        */
        static public function getUserCache() {
                if (!self::$user_cache) {
                        $fast_cache = null;
@@ -44,11 +59,19 @@ class OC_Cache {
                return self::$user_cache;
        }
 
+       /**
+        * get a value from the user cache
+        * @return mixed
+        */
        static public function get($key) {
                $user_cache = self::getUserCache();
                return $user_cache->get($key);
        }
 
+       /**
+        * set a value in the user cache
+        * @return bool
+        */
        static public function set($key, $value, $ttl=0) {
                if (empty($key)) {
                        return false;
@@ -57,19 +80,42 @@ class OC_Cache {
                return $user_cache->set($key, $value, $ttl);
        }
 
+       /**
+        * check if a value is set in the user cache
+        * @return bool
+        */
        static public function hasKey($key) {
                $user_cache = self::getUserCache();
                return $user_cache->hasKey($key);
        }
 
+       /**
+        * remove an item from the user cache
+        * @return bool
+        */
        static public function remove($key) {
                $user_cache = self::getUserCache();
                return $user_cache->remove($key);
        }
 
+       /**
+        * clear the user cache
+        * @return bool
+        */
        static public function clear() {
                $user_cache = self::getUserCache();
                return $user_cache->clear();
        }
 
+       /**
+        * check if a fast memory based cache is available
+        * @return true
+        */
+       static public function isFast() {
+               if(is_null(self::$isFast)){
+                       self::$isFast=function_exists('xcache_set') || function_exists('apc_store');
+               }
+               return self::$isFast;
+       }
+
 }