From 2b747789588e34bce24bd558f7e979a6e0ea8047 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 22 Jul 2012 02:23:24 +0200 Subject: [PATCH] add method to OC_Cache to check whether a fast cache (apc/xdebug/etc) is available --- lib/cache.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/lib/cache.php b/lib/cache.php index 1f269174fa..6f4b3e6e3f 100644 --- a/lib/cache.php +++ b/lib/cache.php @@ -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; + } + }