CC-5555 : Implement simple caching for preferences

cache key creation change.
This commit is contained in:
Naomi 2013-11-11 17:08:15 -05:00
parent 0bae60138f
commit b8a084998e
2 changed files with 14 additions and 8 deletions

View File

@ -3,24 +3,30 @@
class Cache
{
private function createCacheKey($key, $userId = null) {
private function createCacheKey($key, $isUserValue, $userId = null) {
$CC_CONFIG = Config::getConfig();
$a = $CC_CONFIG["apiKey"][0];
$cacheKey = "{$key}{$userId}{$a}";
if ($isUserValue) {
$cacheKey = "{$key}{$userId}{$a}";
}
else {
$cacheKey = "{$key}{$a}";
}
return $cacheKey;
}
public function store($key, $value, $userId = null) {
public function store($key, $value, $isUserValue, $userId = null) {
$cacheKey = self::createCacheKey($key, $userId);
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);
}
}

View File

@ -116,7 +116,7 @@ class Application_Model_Preference
exit;
}
$cache->store($key, $value, $userId);
$cache->store($key, $value, $isUserValue, $userId);
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.");
}
$res = $cache->fetch($key, $userId);
$res = $cache->fetch($key, $isUserValue, $userId);
if ($res !== false) {
Logging::info("returning {$key} {$userId} from cache. = {$res}");
return $res;
@ -176,7 +176,7 @@ class Application_Model_Preference
$res = ($result !== false) ? $result : "";
}
$cache->store($key, $res, $userId);
$cache->store($key, $res, $isUserValue, $userId);
return $res;
}
catch (Exception $e) {