Expand description
Provides a size constrained LRU Cache.
An LRU cache drops the least recently used entry if it about to grow beyond the given limits.
In contrast to prominent caches like Redis itself or memcached, this implementation provides
a special command named LRU.XGET
. The idea is quite simple: Imagine the cache stores data which
is kind of hard to compute (takes some time), but we still want to refresh the contents from
time to time. Now if we detect a stale entry, we’d rather use this entry one more time (but
signal the client, that it should recompute and PUT
an updated value). Now, as we most probably
serve many clients at the same time, we also do not want each client to run the re-computation
in parallel, so we remember that we signalled a refresh and will then again suppress this flag
for a certain period, so that, while one client computes the new data, other clients can still
use the stale cache data without slowing down.
Now, of course this approach can only be used for certain types of cached data, where using stale (or potentially stale) data doesn’t lead to disaster. However, if this trick can be pulled off, this leads to super fast response times along with a nice way of keeping the cache up to date by still using relatively short TTLs.
Another unique feature of this cache is the support of secondary keys. When inserting an entity into the cache, it can be supplied with additional (secondary) keys. These cannot be used to lookup the value but rather to flush one or more values from the cache. This is useful, when a set of cached entities depend on another entity and need to be flushed once this changes.
The cache can store all kinds of values for which the ByteSize trait is implemented. Each cache provides various settings to limit its size (in terms of allocated memory) and also to specify the lifetime (TTL = time to live) for each entry.
The cache module provides an actor which contains a set of caches, as determined in the system config. To enable this, cache::install has to be called.
Modules
- Provides an actor which manages a set of LRU caches for string keys and values.
Structs
- Provides a size constrained LRU cache.
Traits
- Returns the allocated memory in bytes.