AshCommanded.Commanded.SnapshotStore behaviour (AshCommanded v0.1.0)
View SourceDefines the behavior and default implementation for aggregate snapshot storage.
The snapshot store is responsible for storing and retrieving snapshots of aggregates, providing a performance optimization by allowing the system to load the latest snapshot rather than replaying all events from the beginning.
The default implementation uses ETS tables for storage. Alternative implementations can be provided by specifying a custom snapshot store module in the application config.
Summary
Callbacks
Deletes all snapshots for an aggregate.
Gets the latest snapshot for an aggregate by its UUID.
Initializes the snapshot store.
Saves a snapshot of an aggregate.
Functions
Deletes all snapshots for an aggregate.
Gets the latest snapshot for an aggregate by its UUID.
Initializes the snapshot store.
Saves a snapshot of an aggregate.
Callbacks
Deletes all snapshots for an aggregate.
Parameters
source_uuid
- The unique identifier of the aggregatesource_type
- The aggregate module
Returns
:ok
- If the snapshots were deleted successfully{:error, reason}
- If the snapshots could not be deleted
@callback get_snapshot(String.t(), module()) :: {:ok, AshCommanded.Commanded.Snapshot.t()} | :error
Gets the latest snapshot for an aggregate by its UUID.
Parameters
source_uuid
- The unique identifier of the aggregatesource_type
- The aggregate module
Returns
{:ok, snapshot}
- If a snapshot was found:error
- If no snapshot was found
Initializes the snapshot store.
Parameters
config
- Configuration options for the snapshot store
Returns
:ok
- If the snapshot store was initialized successfully{:error, reason}
- If the snapshot store could not be initialized
@callback save_snapshot(AshCommanded.Commanded.Snapshot.t()) :: :ok | {:error, any()}
Saves a snapshot of an aggregate.
Parameters
snapshot
- The snapshot to save
Returns
:ok
- If the snapshot was saved successfully{:error, reason}
- If the snapshot could not be saved
Functions
Deletes all snapshots for an aggregate.
Parameters
source_uuid
- The unique identifier of the aggregatesource_type
- The aggregate module
Returns
:ok
- If the snapshots were deleted successfully{:error, reason}
- If the snapshots could not be deleted
@spec get_snapshot(String.t(), module()) :: {:ok, AshCommanded.Commanded.Snapshot.t()} | :error
Gets the latest snapshot for an aggregate by its UUID.
Parameters
source_uuid
- The unique identifier of the aggregatesource_type
- The aggregate module
Returns
{:ok, snapshot}
- If a snapshot was found:error
- If no snapshot was found
@spec init(any()) :: :ok
Initializes the snapshot store.
Parameters
config
- Configuration options for the snapshot store (unused for ETS implementation)
Returns
:ok
- If the snapshot store was initialized successfully
@spec save_snapshot(AshCommanded.Commanded.Snapshot.t()) :: :ok | {:error, any()}
Saves a snapshot of an aggregate.
Parameters
snapshot
- The snapshot to save
Returns
:ok
- If the snapshot was saved successfully{:error, reason}
- If the snapshot could not be saved