/** * Looks up a value in the cache and returns it. Not existent * keys are caught in this call as well, so you do not need * to call exists first. * * @param string $data_group The Data Group to look in. * @param string $key The key to look up. * @return mixed The cached value on success, false on failure. */ function get($data_group, $key) { if ($this->_cache === null) { return false; } return $this->_cache->get("{$data_group}-{$key}"); }
/** * Sets a given leave key in the cache * * @param string $key The key to look up. * @param mixed $data The data to store. * @param int $timeout how long the data should live in the cache. */ public function put_leaves($key, $data, $timeout = false) { if ($this->_cache === null) { return; } $lang_id = midcom::get('i18n')->get_current_language(); $result = $this->_cache->get("{$this->_prefix}-{$key}"); if (!is_array($result)) { $result = array($lang_id => $data); } else { $result[$lang_id] = $data; } $this->_cache->put("{$this->_prefix}-{$key}", $result, $timeout); }
function check_dl_hit(&$context, &$dl_config) { if ($this->_no_cache || $this->_live_mode) { return false; } $dl_request_id = 'DL' . $this->generate_request_identifier($context, $dl_config); $this->_meta_cache->open(); if (!$this->_meta_cache->exists($dl_request_id)) { $this->_meta_cache->close(); unset($dl_request_id); return false; } $dl_content_id = $this->_meta_cache->get($dl_request_id); if (!$this->_meta_cache->exists($dl_content_id)) { // No expiry information (or other content metadata) in cache $this->_meta_cache->close(); unset($dl_content_id, $dl_request_id); return false; } $dl_metadata = $this->_meta_cache->get($dl_content_id); $this->_meta_cache->close(); if (time() > $dl_metadata['expires']) { // DL content expired unset($dl_metadata, $dl_content_id, $dl_request_id); return false; } unset($dl_metadata); $this->_data_cache->open(); if (!$this->_data_cache->exists($dl_content_id)) { // Ghost read, we have everything but the actual content in cache unset($dl_content_id, $dl_request_id); $this->_data_cache->close(); return false; } echo $this->_data_cache->get($dl_content_id); unset($dl_content_id, $dl_request_id); $this->_data_cache->close(); return true; }