alastairtree / LazyCache

An easy to use thread safe in-memory caching service with a simple developer friendly API for c#
https://nuget.org/packages/LazyCache
MIT License
1.72k stars 159 forks source link

DefaultCacheDurationSeconds is not being honored #121

Closed hermesramos closed 4 years ago

hermesramos commented 4 years ago

Describe the bug DefaultCacheDurationSeconds is not being honored.

To Reproduce public static readonly IAppCache CachingService = new CachingService { DefaultCachePolicy = new CacheDefaults { DefaultCacheDurationSeconds = 1 } };

Even though duration is set to 1 second (this time frame is for testing purpose), no cache entry is being evicted.

Expected behavior Evict all cache entries after 1 second.

** Framework and Platform

alastairtree commented 4 years ago

By default cache eviction is lazy for performance reasons - eviction is only triggered on the next time the item is accessed. So even though an expired item is still in the cache it will not be used, and eviction will be triggered next time you try and access it, and any post eviction callbacks will fire then. If required you can force immediate expiration using ExpirationMode in LazyCache 2.1, see the expiration mode section of the docs for more info.