Problem
The cache uses DateTimeOffset.Now throughout for expiration logic (src/NatsDistributedCache/NatsCache.cs — TTL computation, entry creation, absolute-expiration checks, sliding-window updates). This uses local time and makes expiration behavior impossible to unit-test without real wall-clock delays.
Proposal
Inject TimeProvider (default TimeProvider.System) into NatsCache and replace every DateTimeOffset.Now with _timeProvider.GetUtcNow().
This is the .NET 8+ idiom and enables deterministic, instant expiration unit tests via FakeTimeProvider (Microsoft.Extensions.TimeProvider.Testing), removing reliance on Task.Delay in the time-expiration tests.
Acceptance criteria
- No
DateTimeOffset.Now remains in the library.
- Time-expiration unit tests drive time with
FakeTimeProvider (no real delays).
- DI wiring resolves an optional
TimeProvider, defaulting to TimeProvider.System.
Problem
The cache uses
DateTimeOffset.Nowthroughout for expiration logic (src/NatsDistributedCache/NatsCache.cs— TTL computation, entry creation, absolute-expiration checks, sliding-window updates). This uses local time and makes expiration behavior impossible to unit-test without real wall-clock delays.Proposal
Inject
TimeProvider(defaultTimeProvider.System) intoNatsCacheand replace everyDateTimeOffset.Nowwith_timeProvider.GetUtcNow().This is the .NET 8+ idiom and enables deterministic, instant expiration unit tests via
FakeTimeProvider(Microsoft.Extensions.TimeProvider.Testing), removing reliance onTask.Delayin the time-expiration tests.Acceptance criteria
DateTimeOffset.Nowremains in the library.FakeTimeProvider(no real delays).TimeProvider, defaulting toTimeProvider.System.