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 void Add(ScannedRecordDto record) { lock (_syncLock) { _records.Enqueue(record); while (_records.Count > MaxItems) { _records.TryDequeue(out _); } } } public IReadOnlyCollection GetLastFive() { lock (_syncLock) { return _records.Reverse().ToArray(); } } }