Class InMemorySnapshotStore

java.lang.Object
org.axonframework.eventsourcing.snapshot.inmemory.InMemorySnapshotStore
All Implemented Interfaces:
SnapshotStore

public class InMemorySnapshotStore extends Object implements SnapshotStore
An in-memory implementation of SnapshotStore for testing or lightweight scenarios.

This store keeps snapshots in memory only and does not persist them to any durable storage. It is thread-safe.

Snapshots are stored by their qualified name and identifier.

All operations return CompletableFuture to conform with the SnapshotStore asynchronous API, but they complete immediately since storage is in-memory.

Since:
5.1.0
Author:
John Hendrikx
  • Constructor Details

    • InMemorySnapshotStore

      public InMemorySnapshotStore()
  • Method Details

    • store

      public CompletableFuture<Void> store(QualifiedName qualifiedName, Object identifier, Snapshot snapshot)
      Description copied from interface: SnapshotStore
      Persists a snapshot under the given name and identifier. This replaces any previous snapshot(s) with the same name and identifier.

      This method is asynchronous and returns a CompletableFuture that completes when the snapshot has been durably stored.

      Specified by:
      store in interface SnapshotStore
      Parameters:
      qualifiedName - the name of the snapshot to persist, cannot be null
      identifier - the identifier of the snapshot to persist, cannot be null
      snapshot - the snapshot to persist, cannot be null
      Returns:
      a CompletableFuture that completes when the snapshot has been stored
    • load

      public CompletableFuture<@Nullable Snapshot> load(QualifiedName qualifiedName, Object identifier)
      Description copied from interface: SnapshotStore
      Loads the latest snapshot for a given name and identifier.

      The returned snapshot may have an older or newer version relative to what is expected. The caller is responsible for handling version compatibility or ignoring unusable snapshots.

      This method is asynchronous and returns a CompletableFuture that completes with the snapshot if one exists, or null if no snapshot is available.

      Specified by:
      load in interface SnapshotStore
      Parameters:
      qualifiedName - the name of the snapshot, cannot be null
      identifier - the identifier of the snapshot, cannot be null
      Returns:
      a CompletableFuture containing the snapshot, or containing null if no matching snapshot exists