Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/HttpClient.Cache/InMemory/MemoryCacheOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
14 changes: 6 additions & 8 deletions tests/HttpClient.Cache.Tests/InMemory/MemoryCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand All @@ -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")){
Expand All @@ -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")){
Expand Down