AutoCache.Lib
1.0.0
See the version list below for details.
dotnet add package AutoCache.Lib --version 1.0.0
NuGet\Install-Package AutoCache.Lib -Version 1.0.0
<PackageReference Include="AutoCache.Lib" Version="1.0.0" />
paket add AutoCache.Lib --version 1.0.0
#r "nuget: AutoCache.Lib, 1.0.0"
// Install AutoCache.Lib as a Cake Addin #addin nuget:?package=AutoCache.Lib&version=1.0.0 // Install AutoCache.Lib as a Cake Tool #tool nuget:?package=AutoCache.Lib&version=1.0.0
AutoCache
A lib that makes memory caching a little cleaner. Contains one little helper method with the following interface
T CacheRetrieve<T>(Func<T> callback, CacheItemPolicy cachePolicy = null)
CacheRetrieve will by default use a 5 minute sliding expiration policy for cached items. But can be overridden in the constructor.
What it does
It caches in memory the result of the the entire method it's used in, using the parameters + the method name as a cache key.
Example usage
Say you have this method in your backend:
public int SomeDataById(int id)
{
using(var con = connectionFactory.CreateConnection())
{
return con.Query("a lot of data where id = @id", new { id = id })
}
}
You can encapsulate it with AutoCache like this for quick and easy automatic memory caching:
public int SomeDataById(int id)
{
return AutoCache.CacheRetrieve(() =>
{
using(var con = connectionFactory.CreateConnection())
{
return con.Query("a lot of data where id = @id", new { id = id })
}
});
}
In reality, AutoCache translates the method definition to:
public int SomeDataById(int id)
{
var cacheKey = "SomeDataById" + id.ToString();
if(MemoryCache.Default.Contains(cacheKey))
return MemoryCache.Default[cacheKey];
int result = 0
using(var con = connectionFactory.CreateConnection())
{
result = con.Query("a lot of data where id = @id", new { id = id });
}
MemoryCache.Default.Add(new CacheItem(cacheKey, result), new CacheItemPolicy(0, 5, 0));
return MemoryCache.Default[cacheKey];
});
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AutoCache.Lib:
Package | Downloads |
---|---|
DocumentLab-x64
OCR using Tesseract, ImageMagick and EmguCV and an advanced query language. See the GitHub page for language documentation. |
GitHub repositories
This package is not used by any popular GitHub repositories.