_cache = array(); } /** * @param $key * * @return string */ 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 */ 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 */ 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 */ 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(); } }