Class SizeBasedSnapshotStrategy
- Namespace
- Excalibur.EventSourcing.Snapshots
- Assembly
- Excalibur.EventSourcing.dll
Snapshot strategy based on aggregate size in memory.
public sealed class SizeBasedSnapshotStrategy : ISnapshotStrategy
- Inheritance
-
SizeBasedSnapshotStrategy
- Implements
- Inherited Members
Remarks
Creates a snapshot when the estimated memory size of an aggregate exceeds a threshold. Useful for aggregates with large event payloads or many uncommitted events.
Constructors
SizeBasedSnapshotStrategy(long)
Initializes a new instance of the SizeBasedSnapshotStrategy class.
public SizeBasedSnapshotStrategy(long maxSizeInBytes = 1048576)
Parameters
maxSizeInByteslongMaximum aggregate size in bytes before creating a snapshot. Default is 1MB.
Exceptions
- ArgumentOutOfRangeException
Thrown when max size is zero or negative.
Methods
ShouldCreateSnapshot(IAggregateRoot)
Determines whether a snapshot should be created for the aggregate.
[RequiresUnreferencedCode("Calls System.Text.Json.JsonSerializer.Serialize<TValue>(TValue, JsonSerializerOptions)")]
[RequiresDynamicCode("Calls System.Text.Json.JsonSerializer.Serialize<TValue>(TValue, JsonSerializerOptions)")]
public bool ShouldCreateSnapshot(IAggregateRoot aggregate)
Parameters
aggregateIAggregateRootThe aggregate to check.
Returns
- bool
True if a snapshot should be created, otherwise false.