Перейти к содержимому
Русский

In-memory snapshot store

Это содержимое пока не доступно на вашем языке.

InMemorySnapshotStore keeps snapshots in a Map<persistenceId, Snapshot[]> in process memory. Like InMemoryJournal, it’s the default when no snapshot store is configured — zero setup, ideal for tests, never use in production.

import { ActorSystem, ActorSystemOptions, InMemoryJournal, InMemorySnapshotStore } from 'actor-ts';
// In-memory stores are the default; shown here explicitly:
const actorSystemOptions = ActorSystemOptions.create().withPersistence({
journal: new InMemoryJournal(),
snapshotStore: new InMemorySnapshotStore(),
});
const system = ActorSystem.create('demo', actorSystemOptions);

Implements the SnapshotStore interface — save, loadLatest, loadBefore, delete. Each persistenceId maps to an array of snapshots ordered by sequence number.

  • save(persistenceId, seq, state, options?) — append to the pid’s array.
  • loadLatest(persistenceId, options?) — return the highest-seq snapshot, or None.
  • loadBefore(persistenceId, seq, options?) — return the newest snapshot with sequenceNr < seq, or None.
  • delete(persistenceId, toSeq) — splice off snapshots with seq ≤ toSeq.

The implementation is reference semantics — every other snapshot store must match this behavior (modulo persistence / encryption / compression specifics).

  • Tests — fast, no IO, clean teardown per test.
  • Dev — when you don’t want a real snapshot file lying around between runs.
  • Reference for custom implementations — read the source for the contract.