Page MenuHomePhorge
Diviner Tech Docs PhutilKeyValueCacheStack

final class PhutilKeyValueCacheStack
Phorge Technical Documentation ()

Stacks multiple caches on top of each other, with readthrough semantics:

  • For reads, we try each cache in order until we find all the keys.
  • For writes, we set the keys in each cache.

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.
  • public function getKeys($keys)
  • public function setKeys($keys, $ttl)
  • public function deleteKeys($keys)
  • public function destroyCache()

Configuring the Stack

  • public function setCaches($caches) — Set the caches which comprise this stack.
  • public function setNextTTL($ttl) — Set the readthrough TTL for the next cache operation. The TTL applies to any keys set by the next call to @{method:getKey} or @{method:getKeys}, and is reset after the call finishes.

Other Methods

Methods

public function __get($name)
Inherited

This method is not documented.
Parameters
$name
Return
wild

public function __set($name, $value)
Inherited

This method is not documented.
Parameters
$name
$value
Return
wild

public function current()
Inherited

This method is not documented.
Return
wild

public function key()
Inherited

This method is not documented.
Return
wild

public function next()
Inherited

This method is not documented.
Return
wild

public function rewind()
Inherited

This method is not documented.
Return
wild

public function valid()
Inherited

This method is not documented.
Return
wild

private function throwOnAttemptedIteration()
Inherited

This method is not documented.
Return
wild

public function getPhobjectClassConstant($key, $byte_limit)
Inherited

Phobject

Read the value of a class constant.

This is the same as just typing self::CONSTANTNAME, but throws a more useful message if the constant is not defined and allows the constant to be limited to a maximum length.

Parameters
string$keyName of the constant.
int|null$byte_limitMaximum number of bytes permitted in the value.
Return
stringValue of the constant.

public function isAvailable()
Inherited

PhutilKeyValueCache

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)
Inherited

PhutilKeyValueCache

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)
Inherited

PhutilKeyValueCache

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)
Inherited

PhutilKeyValueCache

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

Parameters
string$keyKey to delete.
Return
this

public function getKeys($keys)

PhutilKeyValueCache

Get data from the cache.

PhutilKeyValueCacheStack
This method is not documented.
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.

public function setKeys($keys, $ttl)

PhutilKeyValueCache

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.

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

public function deleteKeys($keys)

PhutilKeyValueCache

Delete a list of keys from the cache.

PhutilKeyValueCacheStack
This method is not documented.
Parameters
list<string>$keysList of keys to delete.
Return
this

public function destroyCache()

PhutilKeyValueCache

Completely destroy all data in the cache.

PhutilKeyValueCacheStack
This method is not documented.
Return
this

public function setCaches($caches)

Set the caches which comprise this stack.

Parameters
list<PhutilKeyValueCache>$cachesOrdered list of key-value caches.
Return
this

public function setNextTTL($ttl)

Set the readthrough TTL for the next cache operation. The TTL applies to any keys set by the next call to getKey() or getKeys(), and is reset after the call finishes.

// If this causes any caches to fill, they'll fill with a 15-second TTL.
$stack->setNextTTL(15)->getKey('porcupine');

// TTL does not persist; this will use no TTL.
$stack->getKey('hedgehog');
Parameters
int$ttlTTL in seconds.
Return
this