The delegate store to cache
Cache configuration options
Optional Readonlysize?: numberMaximum number of records to cache.
When the cache exceeds this bound, the least-recently-used record is evicted after each miss.
Optional Readonlyttl?: numberMaximum record age in milliseconds.
Records older than this value are treated as misses on the next retrieval and evicted when a sibling miss triggers the TTL sweep. Expiration is checked on every hit, so a stale record is never returned even if the sweep hasn't run yet.
Optional Readonlymatch?: (entry: string, cache: string) => booleanPredicate deciding which cached records an invalidation event discards.
Invoked by both invalidation paths — pre-commit writes on the wrapper and reactive mutation events from the delegate — with the mutated resource's identifier and the identifier carried on each cached record. Return true to evict the record.
An immutable store with caching behaviour
Creates a caching store backed by a delegate.
Serves repeated retrievals from an in-memory cache, sparing the delegate a round-trip whenever a prior retrieval can be reused; this cuts latency and backend load for read-heavy workloads, while writes and eviction keep cached results coherent and bounded.
Retrievals are memoised under an
(entry, model, locale, limit)key, where the model is canonicalised bottom-up so templates differing only in property or element order (including arrays of objects) share a cache entry, widening the set of requests a single cached result can serve.shapeis deliberately excluded from the cache key: the retrieval result must be a pure function of(entry, model, locale, limit), withshapesupplying only structural metadata that does not affect the returned payload.opts.localeis part of the cache key because it selects which localised content a retrieval returns. Unlike the model, the locale priority list is order-significant —["en", "it"]and["it", "en"]key separately — since order encodes language-negotiation preference. An omitted or empty locale list collapses to a single key, distinct from any explicit list.opts.limitis part of the cache key because it caps each selection's#and so changes the returned payload, with an omitted or0limit collapsing to a single unbounded key.opts.plain/opts.depthare excluded: they only accept or reject a model, never altering a successful payload.The cache offers three observable guarantees:
The configurable
matchpredicate selects which cached entries a write invalidates.Transaction Isolation — Inherited from the wrapped Store.
Mutation Events — Inherited from the wrapped Store.