From 7f3b5af439327facf12234ccb55298a4add63ea8 Mon Sep 17 00:00:00 2001 From: ArnaudB88 Date: Tue, 31 Mar 2020 10:33:39 +0200 Subject: [PATCH 1/2] Update CachingService.cs Add RemoveAll() method which creates a new cacheprovider --- LazyCache/CachingService.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 +} From 682b314afa2c0376f2519144786cb862a82ee6c1 Mon Sep 17 00:00:00 2001 From: ArnaudB88 Date: Tue, 31 Mar 2020 10:35:43 +0200 Subject: [PATCH 2/2] Update IAppCache.cs --- LazyCache/IAppCache.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 +}