Ling.Cache
is a cache library that can easily use memory cache or redis cache.
- Package Manager
PM> Install-Package Ling.Cache
- .NET CLI
dotnet add package Ling.Cache
- Add
Cache
in yourappsettings.json
file.
{
...
"Cache": {
"Type": "Memory",
"Configuration": "127.0.0.1:6379,password=,defaultDatabase=1",
"InstanceName": "MyApp"
},
...
}
- Then add
AddDistributedCache()
in your service registration code.
// in Program.cs
builder.Services.AddDistributedCache();
// in Startup.cs
services.AddDistributedCache(options =>
{
options.Type = CacheType.Redis;
options.Configuration = "127.0.0.1:6379,password=,defaultDatabase=1";
options.InstanceName = "MyApp"
});