CC-5555 : Implement simple caching for preferences
cache key creation change.
This commit is contained in:
parent
0bae60138f
commit
b8a084998e
|
@ -3,24 +3,30 @@
|
||||||
class Cache
|
class Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
private function createCacheKey($key, $userId = null) {
|
private function createCacheKey($key, $isUserValue, $userId = null) {
|
||||||
|
|
||||||
$CC_CONFIG = Config::getConfig();
|
$CC_CONFIG = Config::getConfig();
|
||||||
$a = $CC_CONFIG["apiKey"][0];
|
$a = $CC_CONFIG["apiKey"][0];
|
||||||
$cacheKey = "{$key}{$userId}{$a}";
|
|
||||||
|
|
||||||
|
if ($isUserValue) {
|
||||||
|
$cacheKey = "{$key}{$userId}{$a}";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$cacheKey = "{$key}{$a}";
|
||||||
|
}
|
||||||
|
|
||||||
return $cacheKey;
|
return $cacheKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store($key, $value, $userId = null) {
|
public function store($key, $value, $isUserValue, $userId = null) {
|
||||||
|
|
||||||
$cacheKey = self::createCacheKey($key, $userId);
|
$cacheKey = self::createCacheKey($key, $userId);
|
||||||
return apc_store($cacheKey, $value);
|
return apc_store($cacheKey, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetch($key, $userId = null) {
|
public function fetch($key, $isUserValue, $userId = null) {
|
||||||
|
|
||||||
$cacheKey = self::createCacheKey($key, $userId);
|
$cacheKey = self::createCacheKey($key, $isUserValue, $userId);
|
||||||
return apc_fetch($cacheKey);
|
return apc_fetch($cacheKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -116,7 +116,7 @@ class Application_Model_Preference
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cache->store($key, $value, $userId);
|
$cache->store($key, $value, $isUserValue, $userId);
|
||||||
Logging::info("SAVING {$key} {$userId} into cache. = {$value}");
|
Logging::info("SAVING {$key} {$userId} into cache. = {$value}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ class Application_Model_Preference
|
||||||
throw new Exception("User id can't be null for a user preference.");
|
throw new Exception("User id can't be null for a user preference.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = $cache->fetch($key, $userId);
|
$res = $cache->fetch($key, $isUserValue, $userId);
|
||||||
if ($res !== false) {
|
if ($res !== false) {
|
||||||
Logging::info("returning {$key} {$userId} from cache. = {$res}");
|
Logging::info("returning {$key} {$userId} from cache. = {$res}");
|
||||||
return $res;
|
return $res;
|
||||||
|
@ -176,7 +176,7 @@ class Application_Model_Preference
|
||||||
$res = ($result !== false) ? $result : "";
|
$res = ($result !== false) ? $result : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
$cache->store($key, $res, $userId);
|
$cache->store($key, $res, $isUserValue, $userId);
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
|
|
Loading…
Reference in New Issue