diff --git a/LazyCache/CachingService.cs b/LazyCache/CachingService.cs index df091de..ab74675 100644 --- a/LazyCache/CachingService.cs +++ b/LazyCache/CachingService.cs @@ -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/LazyCache.csproj b/LazyCache/LazyCache.csproj index 6dc7659..4ab4505 100644 --- a/LazyCache/LazyCache.csproj +++ b/LazyCache/LazyCache.csproj @@ -20,12 +20,13 @@ 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 - - - + + + 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