Skip to content

MemoryStore ​

MemoryStore implements IStore in process memory. It ships with @chamberu/core because every test needs it.

ts
import { MemoryStore } from '@chamberu/core';

const store = new MemoryStore();
OptionTypeDefaultDescription
clockIClocksystemClockTime source for every expiry decision

How it keeps the contract ​

  • Copies: every value is stored and returned as a structuredClone.
  • Atomicity: its methods never await between a check and the matching write, so in a single Node process each atomic operation is atomic.
  • Expiry: claims, keys and locks compare against clock.now() with the shared rule (expired at exactly T + ttlMs).

It passes the same contract suite every other store must pass.

When to use it ​

  • Tests, with a ControllableClock from @chamberu/test-kit passed to both the store and the engine.
  • Local development and scripts.
  • A single process where losing queued and waiting runs on restart is acceptable.

Not durable

Everything is gone with the process: queued runs, waiting approvals, checkpoints, recorded effects and agent state. It also cannot be shared between replicas. Use a durable store to survive restarts or to run more than one replica.

In tests ​

ts
const clock = new ControllableClock(new Date('2026-01-01T00:00:00Z'));
const store = new MemoryStore({ clock });

await store.acquire('job', 'replica-a', 1_000); // true
await store.acquire('job', 'replica-b', 1_000); // false, held by replica-a

clock.advance(1_000); // a lease expires at exactly T + ttlMs
await store.acquire('job', 'replica-b', 1_000); // true