-
Notifications
You must be signed in to change notification settings - Fork 164
Open
Labels
Description
Describe the bug
DefaultCacheDurationSeconds is being ignored in some code paths. It only appears to be used in AppCacheExtensions
e.g. extension
LazyCache/LazyCache/AppCacheExtensions.cs
Line 74 in e38695b
public static Task<T> GetOrAddAsync<T>(this IAppCache cache, string key, Func<Task<T>> addItemFactory) |
LazyCache/LazyCache/CachingService.cs
Line 182 in 33d055c
public virtual Task<T> GetOrAddAsync<T>(string key, Func<ICacheEntry, Task<T>> addItemFactory) |
To Reproduce
var cache = new CachingService
{
DefaultCachePolicy = {DefaultCacheDurationSeconds = 1}
};
var res1 = await cache.GetOrAddAsync("foo", async x => DateTime.UtcNow.Second);
// wait for the item to expire
await Task.Delay(TimeSpan.FromSeconds(2));
// same key
var res2 = await cache.GetOrAddAsync("foo", async x => DateTime.UtcNow.Second);
// new key
var res3 = await cache.GetOrAddAsync("bar", async x => DateTime.UtcNow.Second);
Console.WriteLine(res1);
Console.WriteLine(res2);
Console.WriteLine(res3);
Expected behavior
A new value generated for each call, with output e.g.
23
25
25
Actual behavior
Same value reused for "foo"
, with output e.g.
23
23
25
Framework and Platform
- OS: Windows 10
- Framework net5.0
- LazyCache Version 2.1.3
Additional context
Similar to the report in #121, although this isn't because of lazy eviction