The delegate store to cache
Cache configuration options, and the default retrieval scope
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 for writes made through the wrapper and for mutation events signalled by the delegate. It receives the
identifier of the mutated resource and the identifier of each cached record, and returns true if the record
is to be evicted.
Optional Readonlyscope?: StoreScopeThe retrieval scope that fills in the members a lookup scope leaves out, one by one, before the lookup is matched against the records already cached. It is a fallback rather than a ceiling, so it never caps the bounds a lookup states for itself, even when they are wider.
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 result can be reused. This cuts latency and backend load for read-heavy workloads, while writes and eviction keep cached results coherent and bounded.
Results are cached by
entry,modelandvirtual, and by thelocaleandlimitof the retrieval scope of lookup. Templates differing only in member or element order share a cached result.shapeis not part of the cache key. A retrieval result MUST depend only onentry,model,virtual,localeandlimit, withshapesupplying structural metadata that does not affect the returned payload.The request
virtualflag is part of the cache key, because virtual and held retrievals of the same entry return different collections. An omitted and afalseflag share a single cached result.The scope
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"]are cached separately. An omitted and an empty locale list share a single cached result, distinct from any explicit list.The scope
limitis part of the cache key, because it caps the page size of each collection and so changes the returned payload. An omitted and a0limit are both closed and share a single cached result, while anInfinitylimit has its own. The scopestatsanddepthare not part of the key. They only accept or reject a model, and never alter a successful payload, so lookups differing only in them share a cached result.The
scopeoption fills in the members a lookup scope leaves out before the key is built. A lookup stating no scope thus shares a cached result with one stating the default bounds explicitly. The wrapped store receives each lookup scope as filled in, so the cached result matches what the lookup would have retrieved.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.