Skip to main content

StateCache

@rotorsoft/act-root


@rotorsoft/act-root / act-http/src/sse / StateCache

Class: StateCache<S>

Defined in: libs/act-http/src/sse/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-http/src/sse/state-cache.ts:17

Parametersโ€‹

maxSize?โ€‹

number = 50

Returnsโ€‹

StateCache<S>

Accessorsโ€‹

sizeโ€‹

Get Signatureโ€‹

get size(): number

Defined in: libs/act-http/src/sse/state-cache.ts:51

Current number of cached entries.

Returnsโ€‹

number

Methodsโ€‹

delete()โ€‹

delete(key): void

Defined in: libs/act-http/src/sse/state-cache.ts:41

Remove a cached entry.

Parametersโ€‹

keyโ€‹

string

Returnsโ€‹

void


entries()โ€‹

entries(): IterableIterator<[string, S]>

Defined in: libs/act-http/src/sse/state-cache.ts:56

Direct access to the underlying map (for iteration).

Returnsโ€‹

IterableIterator<[string, S]>


get()โ€‹

get(key): S | undefined

Defined in: libs/act-http/src/sse/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-http/src/sse/state-cache.ts:46

Check if a key exists in the cache.

Parametersโ€‹

keyโ€‹

string

Returnsโ€‹

boolean


set()โ€‹

set(key, state): void

Defined in: libs/act-http/src/sse/state-cache.ts:32

Set a cached state, evicting the LRU entry if at capacity.

Parametersโ€‹

keyโ€‹

string

stateโ€‹

S

Returnsโ€‹

void