Easy.Cache is a lightweight, high-performance caching library for .NET that supports MemoryCache, Redis, and multi-layer caching with pluggable serialization.
$ dotnet add package Easy.CacheEasy.Cache is a lightweight, flexible caching library for .NET applications supporting multi-layer caching with MemoryCache and Redis. It provides seamless serialization and optional expiration policies.
dotnet add package Easy.Cachebuilder.Services.AddEasyCacheMemory();builder.Services.AddEasyCacheRedis("your-redis-connection-string");builder.Services.AddEasyCacheMultiLayer("your-redis-connection-string");public class TestController : ControllerBase
{
private readonly CacheManager _cache;
public TestController(CacheManager cache)
{
_cache = cache;
}
[HttpGet("set")]
public async Task<IActionResult> SetData()
{
TimeSpan absoluteExpiration = TimeSpan.FromMinutes(10);
TimeSpan slidingExpiration = TimeSpan.FromMinutes(2);
await _cache.SetAsync("user:1", new { Name = "John", Age = 30 }, absoluteExpiration, slidingExpiration);
//or
//for Redis only:
//await _cache.SetAsync("user:1", new { Name = "John", Age = 30 }, absoluteExpiration);
//or
//await _cache.SetAsync("user:1", new { Name = "John", Age = 30 }); // No expiration
return Ok();
}
[HttpGet("get")]
public async Task<IActionResult> GetData()
{
var user = await _cache.GetAsync<dynamic>("user:1");
return Ok(user);
}
}MIT License
� 2025 Elmin Alirzayev / Easy Code Tools