Created
July 15, 2014 15:02
-
-
Save payden/9afa6e0da88ec7b5178c to your computer and use it in GitHub Desktop.
2 layer caching.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function _get_contact_info($contact_id) { | |
//check local process cache first | |
if (!isset($this->_contact_info_cache[$contact_id])) { | |
$memcache_key = "contact_info_cache_" . $contact_id; | |
$memcache_res = $this->cache->get($memcache_key); | |
//then check memcache | |
if ($memcache_res) { | |
$this->_contact_info_cache[$contact_id] = json_decode($memcache_res, true); | |
} else { | |
//fall back to DB retrieval and store in both memcache and local process cache. | |
$contact_info = $this->contacts->get_contact_info($contact_id); | |
$this->_contact_info_cache[$contact_id] = $contact_info; | |
$this->cache->set($memcache_key, json_encode($contact_info), 3600 * 12); | |
} | |
} | |
return $this->_contact_info_cache[$contact_id]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment