add option to only get fast cache

This commit is contained in:
Robin Appelman 2012-07-22 03:21:20 +02:00
parent 51566e87c7
commit 6843beeae9
1 changed files with 41 additions and 16 deletions

View File

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