Created
July 15, 2014 15:57
-
-
Save payden/1c029a85288e52db20cb to your computer and use it in GitHub Desktop.
Yet another thing
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 _set_item_in_memcache($type, $id, $obj) { | |
$mc_key = "cache_{$type}_{$id}"; | |
$this->cache->set($mc_key, json_encode($obj)); | |
} | |
protected function _populate_item_from_memcache($type, $id) { | |
$mc_key = "cache_{$type}_{$id}"; | |
$rv = $this->cache->get($mc_key); | |
if ($rv === false) return; | |
$this->_caches[$type][$id] = json_decode($rv, true); | |
} | |
protected function _get_item_from_cache($callable, $type, $id) { | |
if (!isset($this->_caches[$type])) { | |
$this->_caches[$type] = array(); | |
} | |
if (!isset($this->_caches[$type][$id])) { | |
$this->_populate_item_from_memcache($type, $id); | |
if (!isset($this->_caches[$type][$id])) { | |
$this->_caches[$type][$id] = call_user_func_array($callable, array($id)); | |
$this->_set_item_in_memcache($type, $id, $this->_caches[$type][$id]); | |
} | |
} | |
} | |
protected function _get_contact_info($contact_id) { | |
//check local process cache first | |
$retrieval_func = $this->contacts->get_contact_info; | |
return $this->_get_item_from_cache($retrieval_func, 'contact', $contact_id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment