Interface SnapshotStore
- All Known Implementing Classes:
DefaultSnapshotStore
,NoOpSnapshotStore
Snapshots are serialized representations of an aggregate's state at a certain point in time (i.e., after a certain sequence number). They allow the system to avoid replaying the entire event history for aggregates with large event logs.
This interface defines methods for storing, loading, and deleting such snapshots. Snapshots are typically
used in combination with AggregateRepository
and
EventStore
to optimize aggregate loading.
Usage of this interface is optional—if no snapshot is found, the aggregate is reconstructed from its full event history.
-
Method Summary
Modifier and TypeMethodDescriptiondeleteSnapshot
(Object aggregateId) Deletes the snapshot for the specified aggregate ID.getSnapshot
(Object aggregateId) Retrieves the most recent snapshot for a given aggregate ID, if available.<T> CompletableFuture
<Void> storeSnapshot
(Entity<T> snapshot) Stores a new snapshot for the given aggregate entity.
-
Method Details
-
storeSnapshot
Stores a new snapshot for the given aggregate entity.The snapshot typically contains the latest known state and metadata such as the aggregate ID and sequence number. Storing a snapshot will overwrite any existing snapshot for the same aggregate ID.
- Type Parameters:
T
- The aggregate root type.- Parameters:
snapshot
- The aggregate entity to be stored as a snapshot.- Returns:
- A
CompletableFuture
indicating whether the operation completed successfully.
-
getSnapshot
Retrieves the most recent snapshot for a given aggregate ID, if available.- Type Parameters:
T
- The expected type of the aggregate.- Parameters:
aggregateId
- The ID of the aggregate for which to retrieve a snapshot.- Returns:
- An
Optional
containing the aggregate snapshot if present, otherwise empty.
-
deleteSnapshot
Deletes the snapshot for the specified aggregate ID.- Parameters:
aggregateId
- The ID of the aggregate whose snapshot should be deleted.- Returns:
- A
CompletableFuture
indicating completion of the deletion operation.
-