![]() |
VOOZH | about |
dotnet add package AutoCache.Lib --version 1.1.1
NuGet\Install-Package AutoCache.Lib -Version 1.1.1
<PackageReference Include="AutoCache.Lib" Version="1.1.1" />
<PackageVersion Include="AutoCache.Lib" Version="1.1.1" />Directory.Packages.props
<PackageReference Include="AutoCache.Lib" />Project file
paket add AutoCache.Lib --version 1.1.1
#r "nuget: AutoCache.Lib, 1.1.1"
#:package AutoCache.Lib@1.1.1
#addin nuget:?package=AutoCache.Lib&version=1.1.1Install as a Cake Addin
#tool nuget:?package=AutoCache.Lib&version=1.1.1Install as a Cake Tool
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.
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.
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 net461 is compatible. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
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. |
This package is not used by any popular GitHub repositories.