Skip to content
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 @@ -178,11 +178,15 @@

public virtual ICacheProvider CacheProvider => cacheProvider.Value;

public virtual Task<T> GetOrAddAsync<T>(string key, Func<ICacheEntry, Task<T>> addItemFactory)

Check warning on line 181 in LazyCache/CachingService.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

All 'GetOrAddAsync' method overloads should be adjacent.

See more on https://sonarcloud.io/project/issues?id=alastairtree_LazyCache&issues=AZ6yPr6XW0IbvSn80hKe&open=AZ6yPr6XW0IbvSn80hKe&pullRequest=172
{
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);
}
}
8 changes: 5 additions & 3 deletions LazyCache/LazyCache.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
<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="10.0.10" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="10.0.10" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.10" />
</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 @@
{
cache?.Dispose();
}

public void Compact(double percentage)
{
if (cache is MemoryCache)

Check warning on line 94 in LazyCache/Providers/MemoryCacheProvider.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this type-check-and-cast sequence to use pattern matching.

See more on https://sonarcloud.io/project/issues?id=alastairtree_LazyCache&issues=AZ6yPr82W0IbvSn80hKf&open=AZ6yPr82W0IbvSn80hKf&pullRequest=172
{
var c = cache as MemoryCache;
if (c != null)
c.Compact(percentage);
}
}
}
}