context = $context; $this->cacheId = $cacheId; $this->fallback = $fallback; $this->cacheMiss =& new generic_cache_miss; } /** * Get an object from cache, using the fallback if necessary. */ function get($id) { $result = $this->getCache($id); if (get_class($result) === 'generic_cache_miss') { $result = call_user_func_array($this->fallback, array(&$this, $id)); } return $result; } /** * Set an object in the cache. This function should be overridden * by subclasses. */ function set($id, $value) { return $this->setCache($id, $value); } /** * Flush the cache. */ function flush() { } /** * Set the entire contents of the cache. May (should) be overridden * by subclasses. * @param $array array of id -> value pairs */ function setEntireCache($contents) { $this->flush(); foreach ($contents as $id => $value) { $this->setCache($id, $value); } } /** * Get an object from the cache. This function should be overridden * by subclasses. * @param $id */ function getCache($id) { return $this->cacheMiss; } /** * Set an object in the cache. This function should be overridden * by subclasses. * @param $id * @param $value */ function setCache($id, $value) { } /** * Close the cache. (Optionally overridden by subclasses.) */ function close() { } /** * Get the context. */ function getContext() { return $this->context; } /** * Get the cache ID within its context */ function getCacheId() { return $this->cacheId; } /** * Get the time at which the data was cached. */ function getCacheTime() { // Since it's not really cached, we'll consider it to have been cached just now. return time(); } } ?>