_timeout = intval($config['timeout']); } if (isset($config['prefix'])) { $this->_prefix = $config['prefix']; } } /** * @param $key * @param $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"); } if (!apc_store($this->_prefix . $key, $value, $this->_timeout)) { return FALSE; } return TRUE; } /** * @param $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"); } return apc_fetch($this->_prefix . $key); } /** * @param $key * * @return bool|string[] */ public function delete($key) { return apc_delete($this->_prefix . $key); } public function flush() { $allinfo = apc_cache_info('user'); $keys = $allinfo['cache_list']; $prefix = $this->_prefix . "CRM_"; // Our keys follows this pattern: ([A-Za-z0-9_]+)?CRM_[A-Za-z0-9_]+ $lp = strlen($prefix); // Get prefix length foreach ($keys as $key) { $name = $key['info']; if ($prefix == substr($name, 0, $lp)) { // Ours? apc_delete($this->_prefix . $name); } } return TRUE; } public function clear() { return $this->flush(); } }