add method to OC_Cache to check whether a fast cache (apc/xdebug/etc) is available

This commit is contained in:
Robin Appelman 2012-07-22 02:23:24 +02:00
parent 2a73678fef
commit 2b74778958
1 changed files with 46 additions and 0 deletions

View File

@ -7,9 +7,20 @@
*/ */
class OC_Cache { class OC_Cache {
/**
* @var OC_Cache $user_cache
*/
static protected $user_cache; static protected $user_cache;
/**
* @var OC_Cache $global_cache
*/
static protected $global_cache; static protected $global_cache;
static protected $isFast=null;
/**
* get the global cache
* @return OC_Cache
*/
static public function getGlobalCache() { static public function getGlobalCache() {
if (!self::$global_cache) { if (!self::$global_cache) {
$fast_cache = null; $fast_cache = null;
@ -27,6 +38,10 @@ class OC_Cache {
return self::$global_cache; return self::$global_cache;
} }
/**
* get the user cache
* @return OC_Cache
*/
static public function getUserCache() { static public function getUserCache() {
if (!self::$user_cache) { if (!self::$user_cache) {
$fast_cache = null; $fast_cache = null;
@ -44,11 +59,19 @@ class OC_Cache {
return self::$user_cache; return self::$user_cache;
} }
/**
* get a value from the user cache
* @return mixed
*/
static public function get($key) { static public function get($key) {
$user_cache = self::getUserCache(); $user_cache = self::getUserCache();
return $user_cache->get($key); return $user_cache->get($key);
} }
/**
* set a value in the user cache
* @return bool
*/
static public function set($key, $value, $ttl=0) { static public function set($key, $value, $ttl=0) {
if (empty($key)) { if (empty($key)) {
return false; return false;
@ -57,19 +80,42 @@ class OC_Cache {
return $user_cache->set($key, $value, $ttl); return $user_cache->set($key, $value, $ttl);
} }
/**
* check if a value is set in the user cache
* @return bool
*/
static public function hasKey($key) { static public function hasKey($key) {
$user_cache = self::getUserCache(); $user_cache = self::getUserCache();
return $user_cache->hasKey($key); return $user_cache->hasKey($key);
} }
/**
* remove an item from the user cache
* @return bool
*/
static public function remove($key) { static public function remove($key) {
$user_cache = self::getUserCache(); $user_cache = self::getUserCache();
return $user_cache->remove($key); return $user_cache->remove($key);
} }
/**
* clear the user cache
* @return bool
*/
static public function clear() { static public function clear() {
$user_cache = self::getUserCache(); $user_cache = self::getUserCache();
return $user_cache->clear(); 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;
}
} }