Cache
Stores information temporarily to avoid unneeded network requests.
Cache state
Each piece of data in a cache can be in three different states:
Up-to-date: the last query was not long ago, we consider its result still valid,
Stale: the last query was long enough ago that it deserves to be checked again, but it probably is still valid. In this case, the cache returns the old value and starts a refresh request in the background.
Expired: the last query was too long ago for the data to still be valid. In this case, the cache starts a refresh request and will not return a value until the request finishes. All data that was never previously queried is in this state.
Different cache implementations differ on how they transition data from one state to another. Some cache implementations may not have a 'stale' state. As a user of the cache, you may want to force the state of a specific object if you have more knowledge than the cache, in this case you can use update and expire.
Cache chaining
Cache implementations can be chained. A possible scenario for some data that rarely changes can be:
Cache the data in memory for 5 minutes,
Cache the data in hard storage for 1 hour,
Query the data for real afterward.
Cache chaining is instantiated in the opposite order, like iterators (the last in the chain is the first checked, and delegates to the previous one if they do not have the value). The first element of the chain, and therefore the one responsible for actually starting the request, is cache or batchingCache. Note that both have a few implementation differences, it is not recommended to use them directly without chaining under another implementation.
Parameters
An identifier representing a cached object. Two identifiers refer to the same object if their equals method returns true
.
The type of possible failures which may happen when requesting a value. If the cached operation cannot fail, or if you're using another error-handling strategy, see InfallibleCache.
The type of cached object.
Functions
In-browser Cache layer.
In-browser Cache implementation that is shared between tabs and persists when the browser is closed.
In-memory Cache layer.
In-browser Cache implementation that is cleared when the tab is closed.
Age-based Cache expiration strategy.
Gets the value associated with an id in this cache.
Forces the cache to accept the given values as more recent for their associated identifier than whatever was previously stored.