From b8a084998e27b3ea59bf6cac8dc14ffa86012151 Mon Sep 17 00:00:00 2001 From: Naomi Date: Mon, 11 Nov 2013 17:08:15 -0500 Subject: [PATCH] CC-5555 : Implement simple caching for preferences cache key creation change. --- airtime_mvc/application/models/Cache.php | 16 +++++++++++----- airtime_mvc/application/models/Preference.php | 6 +++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/airtime_mvc/application/models/Cache.php b/airtime_mvc/application/models/Cache.php index 3d89b0649..fc473395a 100644 --- a/airtime_mvc/application/models/Cache.php +++ b/airtime_mvc/application/models/Cache.php @@ -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); } } \ No newline at end of file diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index 7f1656341..660eaf825 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -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) {