using System.Collections.Concurrent; using AVSCartonShipmentVerifier.DTOs; namespace AVSCartonShipmentVerifier.Services; public sealed class InMemoryScanHistoryStore : IScanHistoryStore { private const int MaxItems = 5; private readonly ConcurrentQueue _records = new(); private readonly Lock _syncLock = new(); public Task AddAsync(ScannedRecordDto record, CancellationToken cancellationToken = default) { lock (_syncLock) { _records.Enqueue(record); while (_records.Count > MaxItems) { _records.TryDequeue(out _); } } return Task.CompletedTask; } public Task> GetLastFiveAsync(CancellationToken cancellationToken = default) { lock (_syncLock) { return Task.FromResult>(_records.Reverse().ToArray()); } } }