diff --git a/LazyCache.UnitTests/CachingServiceMemoryCacheProviderTests.cs b/LazyCache.UnitTests/CachingServiceMemoryCacheProviderTests.cs index 42aa3b9..7ca4192 100644 --- a/LazyCache.UnitTests/CachingServiceMemoryCacheProviderTests.cs +++ b/LazyCache.UnitTests/CachingServiceMemoryCacheProviderTests.cs @@ -263,6 +263,15 @@ public void GetOrAddAndThenGetOrAddDifferentTypeDoesLastInWins() Assert.IsInstanceOf(second); } + [Test] + public void GetOrAddAndThenGetOrAddDifferentTypeSuppliesPolicy() + { + sut.GetOrAdd(TestKey, cacheEntry => 123); + sut.GetOrAdd(TestKey, cacheEntry => "itemWithDifferentType", new MemoryCacheEntryOptions { SlidingExpiration = new TimeSpan(750) }); + Thread.Sleep(1500); + Assert.IsNull(sut.Get(TestKey)); + } + [Test] public void GetOrAddAndThenGetValueObjectReturnsCorrectType() { @@ -337,6 +346,15 @@ public async Task GetOrAddAsyncAndThenGetOrAddAsyncDifferentTypeDoesLastInWins() Assert.IsInstanceOf(second); } + [Test] + public async Task GetOrAddAsyncAndThenGetOrAddAsyncDifferentTypeSuppliesPolicy() + { + await sut.GetOrAddAsync(TestKey, cacheEntry => Task.FromResult(new object())); + await sut.GetOrAddAsync(TestKey, cacheEntry => Task.FromResult("itemWithDifferentType"), new MemoryCacheEntryOptions { SlidingExpiration = new TimeSpan(750) }); + await Task.Delay(1500); + Assert.IsNull(sut.Get(TestKey)); + } + [Test] public async Task GetOrAddAsyncAndThenGetAsyncWrongObjectReturnsNull() { diff --git a/LazyCache/CachingService.cs b/LazyCache/CachingService.cs index 30b6754..7e64767 100644 --- a/LazyCache/CachingService.cs +++ b/LazyCache/CachingService.cs @@ -137,7 +137,7 @@ object CacheFactory(ICacheEntry entry) => try { - cacheItem = CacheProvider.GetOrCreate(key, CacheFactory); + cacheItem = CacheProvider.GetOrCreate(key, policy, CacheFactory); } finally { @@ -226,7 +226,7 @@ object CacheFactory(ICacheEntry entry) => try { - cacheItem = CacheProvider.GetOrCreate(key, CacheFactory); + cacheItem = CacheProvider.GetOrCreate(key, policy, CacheFactory); } finally {