Easy.Cache.Core
2026.3.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Easy.Cache.Core --version 2026.3.2
NuGet\Install-Package Easy.Cache.Core -Version 2026.3.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Easy.Cache.Core" Version="2026.3.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Easy.Cache.Core" Version="2026.3.2" />
<PackageReference Include="Easy.Cache.Core" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Easy.Cache.Core --version 2026.3.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Easy.Cache.Core, 2026.3.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Easy.Cache.Core@2026.3.2
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Easy.Cache.Core&version=2026.3.2
#tool nuget:?package=Easy.Cache.Core&version=2026.3.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
6. 通过Aop使用内存缓存对接口、方法进行缓存
1. nuget包引入
必须引入两个包 至少在2024.11.7以上
<PackageReference Include="Easy.Cache.Core" Version="2026.3.2" />
2. 配置
//如果使用内存缓存则不需要配置,如果使用redis缓存则需要配置redis连接字符串
"RedisConfigurations": {
"RedisClients": {
"TestCache": {//单机模式配置(与集群模式配置是一样的)
"ConnectionString": "localhost:6379,abortConnect=false,ssl=false,password=123456"
},
"SentinelCache": {//哨兵模式配置
"ConnectionString": "mymaster,abortConnect=false,ssl=false,password=123456",
"SentinelNodes":[
"localhost:26379",
"localhost:26380",
]
},
"ClusterCache": {//集群模式配置
"ConnectionString": "localhost:6379,abortConnect=false,ssl=false,password=123456"
}
}
}
使用缓存
//开启内存缓存,如果有redis会使用redis,如果没有则会使用内存缓存
builder.Services.AddEasyCache(configuration,"RedisConfigurations");//默认不传就是RedisConfigurations,如果是其他名称需要在这里修改,
2. 使用缓存\缓存切换
public class CacheResultService : ICacheResultService
{
private readonly IEasyCacheService _cacheService;
public CacheResultService(IEasyCacheService cacheService)
{
_cacheService = cacheService;
}
public Student GetStudentAsync(string name)
{
//直接使用缓存对象进行缓存操作
return _cacheService.Get($"student:{name}", "1", 30);
}
}
//缓存客户端切换
public class CacheResultService : ICacheResultService
{
private readonly IEasyCacheService _cacheService;
public CacheResultService(IEasyCacheServiceFactory cacheServiceFactory)
{
_cacheService = cacheServiceFactory.Create("TestCache");//切换到redis缓存客户端进行缓存操作
}
public Student GetStudentAsync(string name)
{
//切换到redis缓存客户端进行缓存操作
return _cacheService.Get($"student:{name}", "1", 30);
}
}
3. 对控制器接口使用内存缓存
builder.Services.AddControllers(options =>
{
//添加自定义的缓存过滤器
options.Filters.Add<EasyCacheResultFilter>();
});
方法缓存使用示例
//同一个方法不同参数会进行多次缓存
//接口注入直接继承IProxyService接口(继承接口后就不需要再手动注入了),方法上使用EasyCacheResultAttribute特性即可
public class CacheResultService : ICacheResultService
{
//缓存5秒
[EasyCacheResult(5)]
public Student GetStudentAsync(string name)
{
return new Student { Name = name };
}
}
public interface ICacheResultService : IProxyService
{
Student GetStudentAsync(string name);
}
控制器缓存使用示例
[HttpGet]
[EasyCacheResult(5)]//缓存5秒
public object Get()
{
_cacheResultService.GetStudentAsync("这是参数");
return "ok";
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Castle.Core (>= 5.1.1)
- CSRedisCore (>= 3.8.804)
- Easy.Common.Core (>= 2025.12.11.2)
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.3.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- WBC66.Autofac.Core (>= 2024.11.7)
-
net7.0
- Castle.Core (>= 5.1.1)
- CSRedisCore (>= 3.8.804)
- Easy.Common.Core (>= 2025.12.11.2)
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.3.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- WBC66.Autofac.Core (>= 2024.11.7)
-
net8.0
- Castle.Core (>= 5.1.1)
- CSRedisCore (>= 3.8.804)
- Easy.Common.Core (>= 2025.12.11.2)
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.3.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- WBC66.Autofac.Core (>= 2024.11.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
直接使用CsRedis/MemoryCache缓存内置自动切换