ActionCache 0.0.4
See the version list below for details.
dotnet add package ActionCache --version 0.0.4
NuGet\Install-Package ActionCache -Version 0.0.4
<PackageReference Include="ActionCache" Version="0.0.4" />
paket add ActionCache --version 0.0.4
#r "nuget: ActionCache, 0.0.4"
// Install ActionCache as a Cake Addin #addin nuget:?package=ActionCache&version=0.0.4 // Install ActionCache as a Cake Tool #tool nuget:?package=ActionCache&version=0.0.4
ActionCache
Register with IMemoryCache
Use the AddActionCacheMemory
extension method to register IMemoryCache
as the cache store. The configuration for MemoryCacheOptions
is exposed as an optional parameter.
builder.Services.AddActionCacheMemory();
Register with Redis
Use the AddActionCacheRedis
extension method to register Redis as the cache store. The configuration for RedisCacheOptions
is exposed as an optional parameter.
builder.Services.AddActionCacheRedis(options =>
options.Configuration = ...);
Register both IMemoryCache and Redis
The two caches can be combined. The IMemoryCache
instance will be checked for a cache hit before Redis.
builder.Services.AddActionCacheMemory();
builder.Services.AddActionCacheRedis(options =>
options.Configuration = ...);
Basic Usage
Add an ActionCacheAttribute
to any controller actions that should be cached. There is a mandatory parameter for the cache namespace which will prefix all entries with whatever is specified.
[HttpPost]
[Route("/")]
[ActionCache(Namespace = "MyNamespace")]
public IActionResult Post()
{
}
[!IMPORTANT] The current implementation only supports action return types of
IActionResult
. Specifically, the action filter that populates the cache looks for anOkObjectResult
returned from the controller action.
Cache Key Creation
Both the route values and the action arguments are serialized then AES encrypted to generate the cache key suffix. This suffix is appended to the string "ActionCache:{Namespace}".
[!NOTE] Any route data from the request, i.e. the area, controller and action names are also added to the key. This is helpful for the case of automatic cache rehydration which will be part of a future release.
Cache Eviction
An ActionCacheEvictionAttribute
can be applied to a controller action. Cache eviction occurs at the namespace level. One or more namespaces can be used separated by a comma. In the example below, both MyNamespace and MyOtherNamespace would have their entries evicted on a successful execution of the action.
[HttpDelete]
[Route("/")]
[ActionCacheEviction(Namespace = "MyNamespace, MyOtherNamespace")]
public IActionResult Delete()
{
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net8.0
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 8.0.1)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.