Skip to content

jzills/action-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

135 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ActionCache

Namespaced response caching for ASP.NET Core — Memory, Redis, SQL Server, and Azure Cosmos DB.

CI CodeQL NuGet Downloads License: MIT .NET

Summary

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.

Features

  • 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.

Installation

ActionCache is available on NuGet:

dotnet add package ActionCache

Targets .NET 8 and .NET 10.

Quickstart

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.

Resources

About

Namespaced response caching for ASP.NET Core — Memory, Redis, SQL Server, and Azure Cosmos DB.

Topics

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages