diff --git a/src/HttpClient.Cache/InMemory/MemoryCacheOptions.cs b/src/HttpClient.Cache/InMemory/MemoryCacheOptions.cs index 4f9f99f..1af2a38 100644 --- a/src/HttpClient.Cache/InMemory/MemoryCacheOptions.cs +++ b/src/HttpClient.Cache/InMemory/MemoryCacheOptions.cs @@ -4,7 +4,7 @@ namespace HttpClient.Cache.InMemory; public class MemoryCacheOptions { - public TimeSpan ExpirationScanFrequency { get; set; } = TimeSpan.FromSeconds(1.0); + public TimeSpan ExpirationScanFrequency { get; set; } = TimeSpan.FromMinutes(1.0); public ISystemClock Clock { get; set; } = new SystemClock(); } \ No newline at end of file diff --git a/tests/HttpClient.Cache.Tests/InMemory/MemoryCacheTests.cs b/tests/HttpClient.Cache.Tests/InMemory/MemoryCacheTests.cs index b028e17..8dde38a 100644 --- a/tests/HttpClient.Cache.Tests/InMemory/MemoryCacheTests.cs +++ b/tests/HttpClient.Cache.Tests/InMemory/MemoryCacheTests.cs @@ -3,15 +3,13 @@ using HttpClient.Cache.InMemory; namespace HttpClient.Cache.Tests.InMemory; - -[CollectionDefinition("Sequential", DisableParallelization = true)] public class MemoryCacheTests { [Fact] public void CreateEntry_Create10NewEntryAndSetValue_CacheContains10Items() { var expiration = TimeSpan.FromHours(1); - var options = new MemoryCacheOptions(); + var options = new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromSeconds(1.0) }; var cache = new MemoryCache(options); for (var i = 1; i <= 10; ++i) @@ -34,18 +32,18 @@ public void CreateEntry_Create10NewEntryAndSetValue_CacheContains10Items() [Fact] public async Task CreateEntry_ExpireAbsoluteExpirationRelativeToNow_CacheIsEmpty() { - var options = new MemoryCacheOptions(); + var options = new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromSeconds(1.0) }; var cache = new MemoryCache(options); using(var entry = cache.CreateEntry("key")){ - entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(3); + entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(2); entry.Value = $"value"; } using (new AssertionScope()) { cache.Count.Should().Be(1); - await Task.Delay(TimeSpan.FromSeconds(4)); + await Task.Delay(TimeSpan.FromSeconds(3)); var value = cache.TryGetValue("key", out var cacheEntry); value.Should().BeFalse(); @@ -58,7 +56,7 @@ public async Task CreateEntry_ExpireAbsoluteExpirationRelativeToNow_CacheIsEmpty public async Task CreateEntry_ExpireSlidingExpiration_CacheIsEmpty() { var expiration = TimeSpan.FromSeconds(2); - var options = new MemoryCacheOptions(); + var options = new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromSeconds(1.0) }; var cache = new MemoryCache(options); using(var entry = cache.CreateEntry("key")){ @@ -82,7 +80,7 @@ public async Task CreateEntry_ExpireSlidingExpiration_CacheIsEmpty() [Fact] public async Task CreateEntry_ExpireAbsoluteDate_CacheIsEmpty() { - var options = new MemoryCacheOptions(); + var options = new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromSeconds(1.0) }; var cache = new MemoryCache(options); using(var entry = cache.CreateEntry("key")){