ActionCache 0.0.2
See the version list below for details.
dotnet add package ActionCache --version 0.0.2
NuGet\Install-Package ActionCache -Version 0.0.2
<PackageReference Include="ActionCache" Version="0.0.2" />
paket add ActionCache --version 0.0.2
#r "nuget: ActionCache, 0.0.2"
// 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
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
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 | 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.AspNetCore.Mvc (>= 2.2.0)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 8.0.1)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.