ActionCache adds a caching layer to ASP.NET Core by annotating your endpoints. Cache a response, evict entries by namespace, or refresh cached actions with a single attribute — against an in-process or distributed backend, or several layered together.
- Attribute-driven — add caching, eviction, or refresh to any endpoint with one attribute. Works with both MVC controllers and Minimal APIs.
- Four backends — in-process Memory, Redis, SQL Server, and Azure Cosmos DB, used individually or layered together.
- Namespaced eviction — group entries under a namespace (with route-parameter
templates like
Account:{id}) and evict a whole namespace in one call. - Cache refresh — re-invoke cached actions to warm entries ahead of expiry.
- Fail-open by default — a backend outage degrades to a cache miss and logs a warning so requests still succeed; opt into fail-closed to propagate errors instead.
ActionCache is available on NuGet:
dotnet add package ActionCacheTargets .NET 8 and .NET 10.
Register a cache backend:
using ActionCache.Common.Extensions;
builder.Services.AddActionCache(options =>
{
options.UseMemoryCache(memory => { });
// or UseRedisCache(...), UseSqlServerCache(...), UseAzureCosmosCache(...)
});Then annotate your endpoints — cache a read, evict on write:
using ActionCache.Attributes;
[HttpGet("forecasts")]
[ActionCache(Namespace = "Forecasts")]
public IActionResult Get() => Ok(_forecasts);
[HttpPost("forecasts")]
[ActionCacheEviction(Namespace = "Forecasts")]
public IActionResult Create(Forecast forecast) => Ok(_repository.Add(forecast));See the full documentation for expiration, route-templated namespaces, multiple backends, cache refresh, and resilience options.