Cache
Cache<
K,E,V> =object
Defined in: Core/Cache.ts:34
A keyed store that reuses successful results and shares in-flight work.
Three policies govern every lookup:
- Freshness — a stored value younger than
ttlis returned without calling the loader. - Single flight — concurrent lookups for one key share a single load instead of starting their own.
- Reuse after expiry — with
staleWhileRevalidate, an expired-but-recent value is returned immediately while one background refresh runs.
Only successful results are stored. A failed load removes its flight and leaves any older
stored value in place, so a transient error does not poison later lookups. Because a stored
value and a shared flight outlive the caller that started them, load takes no cancellation
input.
Example
Section titled “Example”Type Parameters
Section titled “Type Parameters”K
E
V
Properties
Section titled “Properties”
readonlyclear: () =>void
Defined in: Core/Cache.ts:89
Drops every stored value and in-flight lookup.
Lookups already awaiting a load still receive its result, but nothing is stored afterwards.
Returns
Section titled “Returns”void
Cache.invalidate to drop a single key.
readonlyflush: () =>Deferred<void>
Defined in: Core/Cache.ts:101
Waits until no load is running.
A background refresh started by a stale lookup is included, and so is a load started while the flush is waiting, including one started by a loader that runs during the flush. The deferred stays pending while requests keep arriving, so use it before shutdown and in tests, not on a live stream of requests.
Returns
Section titled “Returns”Deferred<void>
Cache.clear to drop entries without waiting for their loads.
invalidate
Section titled “invalidate”
readonlyinvalidate: (key) =>void
Defined in: Core/Cache.ts:79
Drops the stored value and any in-flight lookup for a key.
Callers already awaiting that lookup still receive its result, but the result is not stored afterwards.
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”void
Cache.clear to drop every key at once.
Defined in: Core/Cache.ts:51
Starts a lookup, reusing a stored value when one is fresh enough and joining an in-flight load when one is already running.
The lookup starts when load is called and takes no cancellation input: the load is shared
and its value is retained, so cancelling one caller would either cancel work other callers
need or report an error that is not an application error. A load must not throw and its
deferred must not reject; encode expected failures in the returned Result.
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”Cache.peek to read a stored value without starting a load.
Example
Section titled “Example”
readonlypeek: (key) =>Maybe<V>
Defined in: Core/Cache.ts:69
Reads the last stored value for a key without starting a load.
A stale value is returned when one is still stored. This never refreshes the entry and never changes least-recently-used eviction order.
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”Maybe<V>
Cache.load to load a missing or expired key.
Example
Section titled “Example”
readonlysize: () =>number
Defined in: Core/Cache.ts:106
Returns the number of stored entries. An in-flight lookup is not counted.
Returns
Section titled “Returns”number