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