Path: blob/master/src/infrastructure/cache/PhutilKeyValueCache.php
12241 views
<?php12/**3* Interface to a key-value cache like Memcache or APC. This class provides a4* uniform interface to multiple different key-value caches and integration5* with PhutilServiceProfiler.6*7* @task kvimpl Key-Value Cache Implementation8*/9abstract class PhutilKeyValueCache extends Phobject {101112/* -( Key-Value Cache Implementation )------------------------------------- */131415/**16* Determine if the cache is available. For example, the APC cache tests if17* APC is installed. If this method returns false, the cache is not18* operational and can not be used.19*20* @return bool True if the cache can be used.21* @task kvimpl22*/23public function isAvailable() {24return false;25}262728/**29* Get a single key from cache. See @{method:getKeys} to get multiple keys at30* once.31*32* @param string Key to retrieve.33* @param wild Optional value to return if the key is not found. By34* default, returns null.35* @return wild Cache value (on cache hit) or default value (on cache36* miss).37* @task kvimpl38*/39final public function getKey($key, $default = null) {40$map = $this->getKeys(array($key));41return idx($map, $key, $default);42}434445/**46* Set a single key in cache. See @{method:setKeys} to set multiple keys at47* once.48*49* See @{method:setKeys} for a description of TTLs.50*51* @param string Key to set.52* @param wild Value to set.53* @param int|null Optional TTL.54* @return this55* @task kvimpl56*/57final public function setKey($key, $value, $ttl = null) {58return $this->setKeys(array($key => $value), $ttl);59}606162/**63* Delete a key from the cache. See @{method:deleteKeys} to delete multiple64* keys at once.65*66* @param string Key to delete.67* @return this68* @task kvimpl69*/70final public function deleteKey($key) {71return $this->deleteKeys(array($key));72}737475/**76* Get data from the cache.77*78* @param list<string> List of cache keys to retrieve.79* @return dict<string, wild> Dictionary of keys that were found in the80* cache. Keys not present in the cache are81* omitted, so you can detect a cache miss.82* @task kvimpl83*/84abstract public function getKeys(array $keys);858687/**88* Put data into the key-value cache.89*90* With a TTL ("time to live"), the cache will automatically delete the key91* after a specified number of seconds. By default, there is no expiration92* policy and data will persist in cache indefinitely.93*94* @param dict<string, wild> Map of cache keys to values.95* @param int|null TTL for cache keys, in seconds.96* @return this97* @task kvimpl98*/99abstract public function setKeys(array $keys, $ttl = null);100101102/**103* Delete a list of keys from the cache.104*105* @param list<string> List of keys to delete.106* @return this107* @task kvimpl108*/109abstract public function deleteKeys(array $keys);110111112/**113* Completely destroy all data in the cache.114*115* @return this116* @task kvimpl117*/118abstract public function destroyCache();119120}121122123