diff --git a/LazyCache/CachingService.cs b/LazyCache/CachingService.cs index 4623c5d..f618f72 100644 --- a/LazyCache/CachingService.cs +++ b/LazyCache/CachingService.cs @@ -10,7 +10,7 @@ namespace LazyCache // ReSharper disable once ClassWithVirtualMembersNeverInherited.Global public class CachingService : IAppCache { - private readonly Lazy cacheProvider; + private Lazy cacheProvider; private readonly SemaphoreSlim locker = new SemaphoreSlim(1, 1); @@ -141,6 +141,13 @@ public virtual void Remove(string key) ValidateKey(key); CacheProvider.Remove(key); } + + public virtual void RemoveAll() + { + CacheProvider.Dispose(); + cacheProvider = new Lazy(() => + new MemoryCacheProvider(new MemoryCache(new MemoryCacheOptions()))); + } public virtual ICacheProvider CacheProvider => cacheProvider.Value; @@ -299,4 +306,4 @@ protected virtual void ValidateKey(string key) throw new ArgumentOutOfRangeException(nameof(key), "Cache keys cannot be empty or whitespace"); } } -} \ No newline at end of file +} diff --git a/LazyCache/IAppCache.cs b/LazyCache/IAppCache.cs index b474cbe..eb412a0 100644 --- a/LazyCache/IAppCache.cs +++ b/LazyCache/IAppCache.cs @@ -24,5 +24,7 @@ public interface IAppCache Task GetOrAddAsync(string key, Func> addItemFactory); void Remove(string key); + + void RemoveAll(); } -} \ No newline at end of file +}