mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-10 17:59:38 +08:00
21 lines
678 B
C#
21 lines
678 B
C#
using System.Collections.Concurrent;
|
|
|
|
namespace BuildingBlocks.EventStoreDB.Subscriptions;
|
|
|
|
public class InMemorySubscriptionCheckpointRepository : ISubscriptionCheckpointRepository
|
|
{
|
|
private readonly ConcurrentDictionary<string, ulong> checkpoints = new();
|
|
|
|
public ValueTask<ulong?> Load(string subscriptionId, CancellationToken ct)
|
|
{
|
|
return new(checkpoints.TryGetValue(subscriptionId, out var checkpoint) ? checkpoint : null);
|
|
}
|
|
|
|
public ValueTask Store(string subscriptionId, ulong position, CancellationToken ct)
|
|
{
|
|
checkpoints.AddOrUpdate(subscriptionId, position, (_, _) => position);
|
|
|
|
return ValueTask.CompletedTask;
|
|
}
|
|
}
|