add method to OC_Cache to check whether a fast cache (apc/xdebug/etc) is available
This commit is contained in:
parent
2a73678fef
commit
2b74778958
1 changed files with 46 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue