_cache = array(); } /** * @param $key * * @return string */ public function fileName($key) { if (strlen($key) > 50) { return CIVICRM_TEMPLATE_COMPILEDIR . "CRM_" . md5($key) . ".php"; } return CIVICRM_TEMPLATE_COMPILEDIR . $key . ".php"; } /** * @param string $key * * @return mixed */ public function get($key) { if (array_key_exists($key, $this->_cache)) { return $this->_cache[$key]; } if (!file_exists($this->fileName($key))) { return; } $this->_cache[$key] = unserialize(substr(file_get_contents($this->fileName($key)), 8)); return $this->_cache[$key]; } /** * @param string $key * @param mixed $value */ public function set($key, &$value) { if (file_exists($this->fileName($key))) { return; } $this->_cache[$key] = $value; file_put_contents($this->fileName($key), "fileName($key))) { unlink($this->fileName($key)); } unset($this->_cache[$key]); } /** * @param null $key */ public function flush($key = NULL) { $prefix = "CRM_"; if (!$handle = opendir(CIVICRM_TEMPLATE_COMPILEDIR)) { return; // die? Error? } while (FALSE !== ($entry = readdir($handle))) { if (substr($entry, 0, 4) == $prefix) { unlink(CIVICRM_TEMPLATE_COMPILEDIR . $entry); } } closedir($handle); unset($this->_cache); $this->_cache = array(); } }