Skip to main content

InMemoryIdempotencyStore

@rotorsoft/act-root


@rotorsoft/act-root / act-ops/src/idempotency / InMemoryIdempotencyStore

Class: InMemoryIdempotencyStore

Defined in: libs/act-ops/src/idempotency/in-memory.ts:49

Bounded LRU + TTL implementation of IdempotencyStore for single-process receivers (the wolfdesk demo, integration tests, dev loops). Multi-process receivers should swap for a durable adapter (Postgres unique index, Redis SET NX) โ€” the IdempotencyStore contract stays the same so the call site doesn't change.

Map iteration is insertion-ordered, so:

  • The oldest entry sits at keys().next().value (cheapest to evict).
  • GC walks until the first non-expired entry and stops.

claim is sync; durable adapters return a Promise<boolean> โ€” both satisfy the union return type in the port.

Implementsโ€‹

Constructorsโ€‹

Constructorโ€‹

new InMemoryIdempotencyStore(options?): InMemoryIdempotencyStore

Defined in: libs/act-ops/src/idempotency/in-memory.ts:54

Parametersโ€‹

options?โ€‹

InMemoryIdempotencyStoreOptions

Returnsโ€‹

InMemoryIdempotencyStore

Methodsโ€‹

claim()โ€‹

claim(key, now?): boolean

Defined in: libs/act-ops/src/idempotency/in-memory.ts:63

Atomically claim key for this caller. Returns true if the caller won the claim (the key was fresh and is now recorded), false if another caller already claimed it โ€” the request should be treated as a duplicate.

now is exposed for tests; production callers should leave it undefined so wall-clock is used.

Parametersโ€‹

keyโ€‹

string

now?โ€‹

number = ...

Returnsโ€‹

boolean

Implementation ofโ€‹

IdempotencyStore.claim


clear()โ€‹

clear(): void

Defined in: libs/act-ops/src/idempotency/in-memory.ts:83

Drop every entry โ€” test hook.

Returnsโ€‹

void


size()โ€‹

size(now?): number

Defined in: libs/act-ops/src/idempotency/in-memory.ts:77

Number of entries currently tracked (post-GC at call time).

Parametersโ€‹

now?โ€‹

number = ...

Returnsโ€‹

number