Returns statistics for this cache.
Returns whether a value associated with the specified key exists in the cache.
Returns statistics for the specified entry.
Retrieves the value associated with the specified key if it exists.
Retrieves the value associated with the specified key if it exists. Otherwise computes the value with the lookup function, puts it in the cache, and returns it.
Invalidates the value associated with the specified key.
Returns the approximate number of values in the cache.
A
Cache
is defined in terms of a lookup function that, given a key of typeKey
, can either fail with an error of typeError
or succeed with a value of typeValue
. Getting a value from the cache will either return the previous result of the lookup function if it is available or else compute a new result with the lookup function, put it in the cache, and return it.A cache also has a specified capacity and time to live. When the cache is at capacity the least recently accessed values in the cache will be removed to make room for new values. Getting a value with a life older than the specified time to live will result in a new value being computed with the lookup function and returned when available.
The cache is safe for concurrent access. If multiple fibers attempt to get the same key the lookup function will only be computed once and the result will be returned to all fibers.