Page MenuHomePhabricator
Diviner Phabricator Tech Docs PhutilDirectoryKeyValueCache

final class PhutilDirectoryKeyValueCache
Phabricator Technical Documentation ()

Interface to a directory-based disk cache. Storage persists across requests.

This cache is very very slow, and most suitable for command line scripts which need to build large caches derived from sources like working copies (for example, Diviner). This cache performs better for large amounts of data than PhutilOnDiskKeyValueCache because each key is serialized individually, but this comes at the cost of having even slower reads and writes.

In addition to having slow reads and writes, this entire cache locks for any read or write activity.

Keys for this cache treat the character "/" specially, and encode it as a new directory on disk. This can help keep the cache organized and keep the number of items in any single directory under control, by using keys like "ab/cd/efghijklmn".

Tasks

Key-Value Cache Implementation

  • public function isAvailable()
  • 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()

Cache Storage

Methods

public function isAvailable()

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.

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

PhutilDirectoryKeyValueCache
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.

PhutilDirectoryKeyValueCache
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.

PhutilDirectoryKeyValueCache
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.

PhutilDirectoryKeyValueCache
This method is not documented.
Return
this

public function setCacheDirectory($directory)

This method is not documented.
Parameters
$directory
Return
wild

private function getCacheDirectory()

This method is not documented.
Return
wild

private function getKeyFile($key)

This method is not documented.
Parameters
$key
Return
wild

private function validateKeys($keys)

This method is not documented.
Parameters
array$keys
Return
wild

private function lockCache($wait)

This method is not documented.
Parameters
$wait
Return
wild

private function unlockCache()

This method is not documented.
Return
wild