ActionCache 0.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package ActionCache --version 0.0.4                
NuGet\Install-Package ActionCache -Version 0.0.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ActionCache" Version="0.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ActionCache --version 0.0.4                
#r "nuget: ActionCache, 0.0.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

NuGet Version NuGet Downloads

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 an OkObjectResult 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.6 72 11/14/2024
0.0.5 85 10/27/2024
0.0.4 109 10/20/2024
0.0.3 76 10/14/2024
0.0.2 109 8/7/2024
0.0.1 98 7/14/2024