![]() |
VOOZH | about |
dotnet add package EasyCache.Cache --version 1.0.1
NuGet\Install-Package EasyCache.Cache -Version 1.0.1
<PackageReference Include="EasyCache.Cache" Version="1.0.1" />
<PackageVersion Include="EasyCache.Cache" Version="1.0.1" />Directory.Packages.props
<PackageReference Include="EasyCache.Cache" />Project file
paket add EasyCache.Cache --version 1.0.1
#r "nuget: EasyCache.Cache, 1.0.1"
#:package EasyCache.Cache@1.0.1
#addin nuget:?package=EasyCache.Cache&version=1.0.1Install as a Cake Addin
#tool nuget:?package=EasyCache.Cache&version=1.0.1Install as a Cake Tool
DotNetEasyCache is a simple way to handle caching items in your .Net project. It utilizes iDistributedCache to help handle caching. It can be used with in memory, Redis, or SQL caching.
You can install DotNetEasyCache through Nuget package manager by running the following:
Install-Package EasyCache.Cache -Version 1.0.1
If you use the dotnet CLI you can use the following:
dotnet add package EasyCache.Cache --version 1.0.1
Add to appsettings.json In your appsettings.json you'll need to include the following entry to utilize DotNetEasyCache:
You can use "Memory", "Redis", or "Sql" as the CacheHandler value.
"EasyCache": {
"CacheHandler": "Memory",
"Redis": {
"Host": "127.0.0.1:6379",
"Instance": "0"
},
"Sql": {
"CacheConnectionString": "",
"SchemaName": "",
"TableName": ""
}
}
To create a SQL Server cached item table in a SQL Server instance, you can use the sql-cache tool. The tool creates a table with the name and schema that you specify.
Create a table in SQL Server by running the sql-cache create command. Provide the SQL Server instance (Data Source), database (Initial Catalog), schema (for example, dbo), and table name (for example, TestCache):
You'll also want to use that same connection string, schema, and table name in your appsettings.json
dotnet sql-cache create "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=DistCache;Integrated Security=True;" dbo TestCache
Program.cs Changes
Add the following line to your program.cs file:
builder.Services.SetEasyCacheServices();
This will implement all the DotNetEasyCache required services.
If you are using async method you can add "Async" to the end of the method you are using. ex:
_easyCache.Put("key", "value", seconds);
would become
await _easyCache.PutAsync("key", "value", seconds);
You can utilize dependency injection to bring the DotNetEasyCache into your project files. An example when using DotNetEasyCache in your a controller can be seen here:
private readonly IEasyCache _easyCache;
public IndexModel(IEasyCache easyCache)
{
_easyCache = easyCache;
}
You may use the Put method to store items in the cache. The Put method requires you to set an expiration in seconds.
The "key" value is the name you want your cache item to be stored as, and the "value" is what you are storing.
When using DotNetEasyCache in the DI container you can use the following:
var seconds = 10;
_easyCache.Put("key", "value", seconds);
To store an item that does not expire you can use the Forever method. This will store an item in cache until it is removed manually
_easyCache.Forever("key", "value");
The Get method is used to retrieve items from the cache. If the item does not exist in the cache, null will be returned.
_easyCache.Get("key");
You may remove items from the cache using the forget method:
_easyCache.Forget("key")
The Exists method can be used to determine if an item exists in the cache. If the value is null this method will return false
_easyCache.Exists("key");
DotNetEasyCache is open-sourced software licensed under the MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.