Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposes Compact #172

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions LazyCache/CachingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ public virtual Task<T> GetOrAddAsync<T>(string key, Func<ICacheEntry, Task<T>> a
return GetOrAddAsync(key, addItemFactory, null);
}

public virtual void Compact(double percentage)
{
CacheProvider.Compact(percentage);
}
public virtual async Task<T> GetOrAddAsync<T>(string key, Func<ICacheEntry, Task<T>> addItemFactory,
MemoryCacheEntryOptions policy)
{
Expand Down
1 change: 1 addition & 0 deletions LazyCache/ICacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public interface ICacheProvider : IDisposable
void Remove(string key);
Task<T> GetOrCreateAsync<T>(string key, Func<ICacheEntry, Task<T>> func);
bool TryGetValue<T>(object key, out T value);
void Compact(double percentage);
}
}
7 changes: 4 additions & 3 deletions LazyCache/LazyCache.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
<PackageTags>Caching Performance Speed In-memory IMemoryCache Generics ServiceCacheing Lazy Cache Lazy-Load MemoryCache CachingService AppCache ApplicationCache Memcached</PackageTags>
<PackageReleaseNotes>See https://raw.githubusercontent.com/alastairtree/LazyCache/master/ReleaseNotes.md</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

<ItemGroup>
<None Include="..\artwork\logo-128.png" Pack="true" PackagePath=""/>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.1.0" />
<None Include="..\artwork\logo-128.png" Pack="true" PackagePath="" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions LazyCache/Mocks/MockCacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@ public bool TryGetValue<T>(object key, out T value)
public void Dispose()
{
}

public void Compact(double percentage)
{

}
}
}
10 changes: 10 additions & 0 deletions LazyCache/Providers/MemoryCacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}