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 * @param null|int|\DateInterval $ttl * @return bool */ public function set($key, $value, $ttl = NULL) { if ($ttl !== NULL) { throw new \RuntimeException("FIXME: " . __CLASS__ . "::set() should support non-NULL TTL"); } CRM_Core_BAO_Cache::setItem($value, $this->group, $key, $this->componentID); $this->frontCache[$key] = $value; return TRUE; } /** * @param string $key * @param mixed $default * * @return mixed */ public function get($key, $default = NULL) { if ($default !== NULL) { throw new \RuntimeException("FIXME: " . __CLASS__ . "::get() only supports NULL default"); } 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 * @return bool */ public function delete($key) { CRM_Core_BAO_Cache::deleteGroup($this->group, $key, FALSE); CRM_Core_BAO_Cache::$_cache = NULL; // FIXME: remove multitier cache CRM_Utils_Cache::singleton()->flush(); // FIXME: remove multitier cache unset($this->frontCache[$key]); return TRUE; } public function flush() { CRM_Core_BAO_Cache::deleteGroup($this->group, NULL, FALSE); CRM_Core_BAO_Cache::$_cache = NULL; // FIXME: remove multitier cache CRM_Utils_Cache::singleton()->flush(); // FIXME: remove multitier cache $this->frontCache = array(); return TRUE; } public function clear() { return $this->flush(); } public function prefetch() { $this->frontCache = CRM_Core_BAO_Cache::getItems($this->group, $this->componentID); } }