Class TimeBasedSnapshotStrategy
- Namespace
- Excalibur.EventSourcing.Snapshots
- Assembly
- Excalibur.EventSourcing.dll
Snapshot strategy based on time intervals.
public sealed class TimeBasedSnapshotStrategy : ISnapshotStrategy
- Inheritance
-
TimeBasedSnapshotStrategy
- Implements
- Inherited Members
Remarks
Creates snapshots when a specified time interval has elapsed since the last snapshot. Useful for aggregates that are frequently accessed but may not have many events.
Constructors
TimeBasedSnapshotStrategy(TimeSpan)
Initializes a new instance of the TimeBasedSnapshotStrategy class.
public TimeBasedSnapshotStrategy(TimeSpan interval)
Parameters
intervalTimeSpanTime interval between snapshots.
Exceptions
- ArgumentOutOfRangeException
Thrown when interval is zero or negative.
Methods
ClearTrackedTimes()
Clears the tracked snapshot times for all aggregates.
public void ClearTrackedTimes()
GetLastSnapshotTime(string)
Gets the last snapshot time for a specific aggregate.
public DateTimeOffset? GetLastSnapshotTime(string aggregateId)
Parameters
aggregateIdstringThe aggregate ID.
Returns
- DateTimeOffset?
The last snapshot time, or null if not tracked.
ShouldCreateSnapshot(IAggregateRoot)
Determines whether a snapshot should be created for the aggregate.
[RequiresUnreferencedCode("Snapshot strategy evaluation may require types that cannot be statically analyzed. Consider using source generation.")]
[RequiresDynamicCode("Snapshot strategy evaluation may require dynamic code generation which is not compatible with AOT compilation.")]
public bool ShouldCreateSnapshot(IAggregateRoot aggregate)
Parameters
aggregateIAggregateRootThe aggregate to check.
Returns
- bool
True if a snapshot should be created, otherwise false.