group = $config['group']; } else { throw new RuntimeException("Cannot construct SqlGroup cache: missing group"); } if (isset($config['componentID'])) { $this->componentID = $config['componentID']; } else { $this->componentID = NULL; } $this->frontCache = array(); if (CRM_Utils_Array::value('prefetch', $config, TRUE)) { $this->prefetch(); } } /** * @param string $key * @param mixed $value */ public function set($key, &$value) { CRM_Core_BAO_Cache::setItem($value, $this->group, $key, $this->componentID); $this->frontCache[$key] = $value; } /** * @param string $key * * @return mixed */ public function get($key) { if (! array_key_exists($key, $this->frontCache)) { $this->frontCache[$key] = CRM_Core_BAO_Cache::getItem($this->group, $key, $this->componentID); } return $this->frontCache[$key]; } /** * @param $key * @param null $default * * @return mixed */ public function getFromFrontCache($key, $default = NULL) { return CRM_Utils_Array::value($key, $this->frontCache, $default); } /** * @param string $key */ public function delete($key) { CRM_Core_BAO_Cache::deleteGroup($this->group, $key); unset($this->frontCache[$key]); } public function flush() { CRM_Core_BAO_Cache::deleteGroup($this->group); $this->frontCache = array(); } public function prefetch() { $this->frontCache = CRM_Core_BAO_Cache::getItems($this->group, $this->componentID); } }