ActionCache 0.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package ActionCache --version 0.0.2                
NuGet\Install-Package ActionCache -Version 0.0.2                
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.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ActionCache --version 0.0.2                
#r "nuget: ActionCache, 0.0.2"                
#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.2

// Install ActionCache as a Cake Tool
#tool nuget:?package=ActionCache&version=0.0.2                

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

An ActionCacheKeyAttribute can be applied to any parameters. In the case of a complex object, the instance will be serialized as JSON an appended to the cache entry key.

[HttpPost]
[Route("/")]
[ActionCache(Namespace = "MyNamespace")]
public IActionResult Post(
    [ActionCacheKey(Order = 1)]int id, 
    [ActionCacheKey(Order = 2)]DateTime date,
    [ActionCacheKey(Order = 3)]SampleModel model
)
{
}

[!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. In the example below, both MyNamespace and MyOtherNamespace would have their entries evicted on a successful execution of the action.

[HttpDelete]
[Route("/")]
[ActionCacheEviction(Namespaces = "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 69 11/14/2024
0.0.5 84 10/27/2024
0.0.4 108 10/20/2024
0.0.3 75 10/14/2024
0.0.2 108 8/7/2024
0.0.1 97 7/14/2024