From 0d3e5647e46fce9cf67f1ae2a1bb2ab3fcc0a30a Mon Sep 17 00:00:00 2001 From: "judahreeves@yahoo.com" Date: Tue, 18 Jan 2022 23:18:23 -0500 Subject: [PATCH 1/4] Supports Compact as implemented by MemoryCache --- LazyCache/CachingService.cs | 6 +++++- LazyCache/ICacheProvider.cs | 1 + LazyCache/Mocks/MockCacheProvider.cs | 5 +++++ LazyCache/Providers/MemoryCacheProvider.cs | 10 ++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/LazyCache/CachingService.cs b/LazyCache/CachingService.cs index df091de..92162ec 100644 --- a/LazyCache/CachingService.cs +++ b/LazyCache/CachingService.cs @@ -43,7 +43,7 @@ public CachingService(ICacheProvider cache) : this(() => cache) = new Lazy(() => new MemoryCacheProvider( new MemoryCache( - new MemoryCacheOptions()) + new MemoryCacheOptions() ) )); /// @@ -183,6 +183,10 @@ public virtual Task GetOrAddAsync(string key, Func> a return GetOrAddAsync(key, addItemFactory, null); } + public virtual void Compact(double percentage) + { + CacheProvider.Compact(percentage); + } public virtual async Task GetOrAddAsync(string key, Func> addItemFactory, MemoryCacheEntryOptions policy) { diff --git a/LazyCache/ICacheProvider.cs b/LazyCache/ICacheProvider.cs index d96c257..d2e2bad 100644 --- a/LazyCache/ICacheProvider.cs +++ b/LazyCache/ICacheProvider.cs @@ -13,5 +13,6 @@ public interface ICacheProvider : IDisposable void Remove(string key); Task GetOrCreateAsync(string key, Func> func); bool TryGetValue(object key, out T value); + void Compact(double percentage); } } \ No newline at end of file diff --git a/LazyCache/Mocks/MockCacheProvider.cs b/LazyCache/Mocks/MockCacheProvider.cs index 019eaf4..f79179d 100644 --- a/LazyCache/Mocks/MockCacheProvider.cs +++ b/LazyCache/Mocks/MockCacheProvider.cs @@ -43,5 +43,10 @@ public bool TryGetValue(object key, out T value) public void Dispose() { } + + public void Compact(double percentage) + { + + } } } \ No newline at end of file diff --git a/LazyCache/Providers/MemoryCacheProvider.cs b/LazyCache/Providers/MemoryCacheProvider.cs index bbee381..6a95730 100644 --- a/LazyCache/Providers/MemoryCacheProvider.cs +++ b/LazyCache/Providers/MemoryCacheProvider.cs @@ -88,5 +88,15 @@ public void Dispose() { cache?.Dispose(); } + + public void Compact(double percentage) + { + if (cache is MemoryCache) + { + var c = cache as MemoryCache; + if (c != null) + c.Compact(percentage); + } + } } } \ No newline at end of file From c467e90b91424cc52b90df8f0b12a20a6b4b8605 Mon Sep 17 00:00:00 2001 From: "judahreeves@yahoo.com" Date: Tue, 18 Jan 2022 23:20:09 -0500 Subject: [PATCH 2/4] Remove whitespace --- LazyCache/CachingService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LazyCache/CachingService.cs b/LazyCache/CachingService.cs index 92162ec..ab74675 100644 --- a/LazyCache/CachingService.cs +++ b/LazyCache/CachingService.cs @@ -43,7 +43,7 @@ public CachingService(ICacheProvider cache) : this(() => cache) = new Lazy(() => new MemoryCacheProvider( new MemoryCache( - new MemoryCacheOptions() ) + new MemoryCacheOptions()) )); /// From 46306a198e84046d662de9c2cf584be80b511980 Mon Sep 17 00:00:00 2001 From: "judahreeves@yahoo.com" Date: Thu, 8 Feb 2024 20:42:12 -0500 Subject: [PATCH 3/4] Nuget updates --- LazyCache/LazyCache.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/LazyCache/LazyCache.csproj b/LazyCache/LazyCache.csproj index 6dc7659..7573ce8 100644 --- a/LazyCache/LazyCache.csproj +++ b/LazyCache/LazyCache.csproj @@ -23,9 +23,9 @@ - - - + + + From 1752087bed992fee6aca67ec46781dbb28ba7cfa Mon Sep 17 00:00:00 2001 From: "judahreeves@yahoo.com" Date: Sun, 12 May 2024 20:41:55 -0400 Subject: [PATCH 4/4] Proj Changes --- LazyCache/LazyCache.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/LazyCache/LazyCache.csproj b/LazyCache/LazyCache.csproj index 7573ce8..4ab4505 100644 --- a/LazyCache/LazyCache.csproj +++ b/LazyCache/LazyCache.csproj @@ -20,6 +20,7 @@ Caching Performance Speed In-memory IMemoryCache Generics ServiceCacheing Lazy Cache Lazy-Load MemoryCache CachingService AppCache ApplicationCache Memcached See https://raw.githubusercontent.com/alastairtree/LazyCache/master/ReleaseNotes.md MIT + AnyCPU;x64