Page MenuHomeGitPull.it
Diviner Tech Docs PhutilKeyValueCache

abstract class PhutilKeyValueCache
Phorge Technical Documentation ()

Interface to a key-value cache like Memcache or APC. This class provides a uniform interface to multiple different key-value caches and integration with PhutilServiceProfiler.

Tasks

Key-Value Cache Implementation

  • public function isAvailable() — Determine if the cache is available. For example, the APC cache tests if APC is installed. If this method returns false, the cache is not operational and can not be used.
  • final public function getKey($key, $default) — Get a single key from cache. See @{method:getKeys} to get multiple keys at once.
  • final public function setKey($key, $value, $ttl) — Set a single key in cache. See @{method:setKeys} to set multiple keys at once.
  • final public function deleteKey($key) — Delete a key from the cache. See @{method:deleteKeys} to delete multiple keys at once.
  • abstract public function getKeys($keys) — Get data from the cache.
  • abstract public function setKeys($keys, $ttl) — Put data into the key-value cache.
  • abstract public function deleteKeys($keys) — Delete a list of keys from the cache.
  • abstract public function destroyCache() — Completely destroy all data in the cache.

Methods

public function isAvailable()

Determine if the cache is available. For example, the APC cache tests if APC is installed. If this method returns false, the cache is not operational and can not be used.

Return
boolTrue if the cache can be used.

final public function getKey($key, $default)

Get a single key from cache. See getKeys() to get multiple keys at once.

Parameters
string$keyKey to retrieve.
wild$defaultOptional value to return if the key is not found. By default, returns null.
Return
wildCache value (on cache hit) or default value (on cache miss).

final public function setKey($key, $value, $ttl)

Set a single key in cache. See setKeys() to set multiple keys at once.

See setKeys() for a description of TTLs.

Parameters
string$keyKey to set.
wild$valueValue to set.
int|null$ttlOptional TTL.
Return
this

final public function deleteKey($key)

Delete a key from the cache. See deleteKeys() to delete multiple keys at once.

Parameters
string$keyKey to delete.
Return
this

abstract public function getKeys($keys)

Get data from the cache.

Parameters
list<string>$keysList of cache keys to retrieve.
Return
dict<string, wild>Dictionary of keys that were found in the cache. Keys not present in the cache are omitted, so you can detect a cache miss.

abstract public function setKeys($keys, $ttl)

Put data into the key-value cache.

With a TTL ("time to live"), the cache will automatically delete the key after a specified number of seconds. By default, there is no expiration policy and data will persist in cache indefinitely.

Parameters
dict<string,$keyswild> Map of cache keys to values.
int|null$ttlTTL for cache keys, in seconds.
Return
this

abstract public function deleteKeys($keys)

Delete a list of keys from the cache.

Parameters
list<string>$keysList of keys to delete.
Return
this

abstract public function destroyCache()

Completely destroy all data in the cache.

Return
this