3 class CRM_Utils_Cache_SerializeCache
implements CRM_Utils_Cache_Interface
{
6 * The cache storage container, an array by default, stored in a file under templates
13 * @param array $config an array of configuration params
17 function __construct($config) {
18 $this->_cache
= array();
21 function fileName ($key) {
22 if (strlen($key) > 50)
23 return CIVICRM_TEMPLATE_COMPILEDIR
."CRM_".md5($key).".php";
24 return CIVICRM_TEMPLATE_COMPILEDIR
.$key.".php";
28 if (array_key_exists($key,$this->_cache
))
29 return $this->_cache
[$key];
31 if (!file_exists($this->fileName ($key))) {
34 $this->_cache
[$key] = unserialize (substr (file_get_contents ($this->fileName ($key)),8));
35 return $this->_cache
[$key];
38 function set($key, &$value) {
39 if (file_exists($this->fileName ($key))) {
42 $this->_cache
[$key] = $value;
43 file_put_contents ($this->fileName ($key),"<?php //".serialize ($value));
46 function delete($key) {
47 if (file_exists($this->fileName ($key))) {
48 unlink ($this->fileName ($key));
50 unset($this->_cache
[$key]);
53 function flush($key =null) {
55 if (!$handle = opendir(CIVICRM_TEMPLATE_COMPILEDIR
)) {
56 return; // die? Error?
58 while (false !== ($entry = readdir($handle))) {
59 if (substr ($entry,0,4) == $prefix) {
60 unlink (CIVICRM_TEMPLATE_COMPILEDIR
.$entry);
65 $this->_cache
= array();