Skip to content

Namespaced response caching for ASP.NET Core

Cache a controller action or a Minimal API endpoint with one attribute. Evict and refresh whole namespaces without knowing a single key.

[HttpGet("forecasts")]
[ActionCache(Namespace = "Forecasts")]
public IActionResult Get() => Ok(_repository.All());

[HttpPost("forecasts")]
[ActionCacheEviction(Namespace = "Forecasts")]
public IActionResult Create(Forecast forecast) => Ok(_repository.Add(forecast));

Cache a read. Drop the whole namespace on write. No keys to track, and nothing else to wire up.

Choosing a backend

They are interchangeable, and they compose — see layered backends.

MemoryRedisSQL ServerCosmos DB
PackageActionCacheActionCache.RedisActionCache.SqlServerActionCache.AzureCosmos
Shared across instancesNoYesYesYes
LockingSemaphoreSlimatomic Luasp_getapplockatomic
Distributed single flightYesYes
ExpiryIMemoryCacheTTL + keyspace eventsSqlServerCachecontainer TTL

Targets .NET 8 and .NET 10 · Read the documentation