StateCache
@rotorsoft/act-root / act-sse/src / StateCache
Class: StateCache<S>
Defined in: libs/act-sse/src/state-cache.ts:13
Generic LRU cache for aggregate state objects.
Keyed by stream ID. Each entry stores the full state (with _v from the
event store). Used as the "previous state" baseline for computing patches,
and as the fast path for reconnects.
The cache is shared between the broadcast hot path and read queries. Projections should maintain their own cache to avoid double-apply bugs.
Type Parameters
S
S extends BroadcastState = BroadcastState
Constructors
Constructor
new StateCache<
S>(maxSize?):StateCache<S>
Defined in: libs/act-sse/src/state-cache.ts:17
Parameters
maxSize?
number = 50
Returns
StateCache<S>
Accessors
size
Get Signature
get size():
number
Defined in: libs/act-sse/src/state-cache.ts:53
Current number of cached entries.
Returns
number
Methods
delete()
delete(
key):void
Defined in: libs/act-sse/src/state-cache.ts:43
Remove a cached entry.
Parameters
key
string
Returns
void
entries()
entries():
IterableIterator<[string,S]>
Defined in: libs/act-sse/src/state-cache.ts:58
Direct access to the underlying map (for iteration).
Returns
IterableIterator<[string, S]>
get()
get(
key):S|undefined
Defined in: libs/act-sse/src/state-cache.ts:22
Get a cached state, promoting it to MRU position.
Parameters
key
string
Returns
S | undefined
has()
has(
key):boolean
Defined in: libs/act-sse/src/state-cache.ts:48
Check if a key exists in the cache.
Parameters
key
string
Returns
boolean
set()
set(
key,state):void
Defined in: libs/act-sse/src/state-cache.ts:33
Set a cached state, evicting the LRU entry if at capacity.
Parameters
key
string
state
S
Returns
void