diff --git a/LazyCache/CachingService.cs b/LazyCache/CachingService.cs index 4623c5d..e1f08fb 100644 --- a/LazyCache/CachingService.cs +++ b/LazyCache/CachingService.cs @@ -93,6 +93,7 @@ object CacheFactory(ICacheEntry entry) => new Lazy(() => { var result = addItemFactory(entry); + SetAbsoluteExpirationFromRelative(entry); EnsureEvictionCallbackDoesNotReturnTheAsyncOrLazy(entry.PostEvictionCallbacks); return result; }); @@ -136,6 +137,15 @@ object CacheFactory(ICacheEntry entry) => } } + private static void SetAbsoluteExpirationFromRelative(ICacheEntry entry) + { + if (!entry.AbsoluteExpirationRelativeToNow.HasValue) return; + + var absoluteExpiration = DateTimeOffset.UtcNow + entry.AbsoluteExpirationRelativeToNow.Value; + if (!entry.AbsoluteExpiration.HasValue || absoluteExpiration < entry.AbsoluteExpiration) + entry.AbsoluteExpiration = absoluteExpiration; + } + public virtual void Remove(string key) { ValidateKey(key); @@ -163,6 +173,7 @@ object CacheFactory(ICacheEntry entry) => new AsyncLazy(() => { var result = addItemFactory(entry); + SetAbsoluteExpirationFromRelative(entry); EnsureEvictionCallbackDoesNotReturnTheAsyncOrLazy(entry.PostEvictionCallbacks); return result; }); diff --git a/ReleaseNotes.md b/ReleaseNotes.md index ec31aa0..aefd43b 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,5 +1,9 @@ # Release notes for LazyCache # +## Version 2.0.5 +- Fix #85 and #100 Absolute expiration not working with TimeSpan. Thank you to @Meberem and @Sinhk. +- Fix #124 casing for PackageReference - by @jnyrup + ## Version 2.0.4 - Fix #82 Make constructor resolution specific when using aspnet core dependency injection