Immediate.Cache
2.0.1
See the version list below for details.
dotnet add package Immediate.Cache --version 2.0.1
NuGet\Install-Package Immediate.Cache -Version 2.0.1
<PackageReference Include="Immediate.Cache" Version="2.0.1" />
<PackageVersion Include="Immediate.Cache" Version="2.0.1" />
<PackageReference Include="Immediate.Cache" />
paket add Immediate.Cache --version 2.0.1
#r "nuget: Immediate.Cache, 2.0.1"
#:package Immediate.Cache@2.0.1
#addin nuget:?package=Immediate.Cache&version=2.0.1
#tool nuget:?package=Immediate.Cache&version=2.0.1
Immediate.Cache
Immediate.Cache is a collection of classes that simplify caching responses from Immediate.Handlers handlers.
Installing Immediate.Cache
dotnet add package Immediate.Cache
Using Immediate.Cache
Creating a Cache
Create a class and apply the [CacheFor<>] attribute, targeting a handler. Add a TransformKey method to transform a
request into a cache key. For example:
[Handler]
public static partial class GetValue
{
public sealed record Query(int Value);
public sealed record Response(int Value);
private static ValueTask<Response> HandleAsync(
Query query,
CancellationToken _
) => ValueTask.FromResult(new Response(query.Value));
}
[CacheFor<GetValue>]
public sealed class GetValueCache
{
protected override string TransformKey(GetValue.Query request) =>
$"GetValue(query: {request.Value})";
}
In this case, the GetValueCache class will serve as a cache for the GetValue IH handler.
Adding generated caches to the IServiceCollection collection
In your Program.cs, add a call to services.AddXxxCaches(), where Xxx is the application identifier. By default,
this is the short form of the assembly name. For example:
- For a project named
Web, it will beservices.AddWebCaches() - For a project named
Application.Web, it will beservices.AddApplicationWebCaches()
However, this name can be overridden using [assembly: ImmediateAssemblyIdentifierAttribute("SomeIdentifier")].
Retrieve Data From the Cache
Using an instance of the GetValueCache class that you have created above, you can simply call:
var response = await cache.GetValue(request, token);
If there is a cached value, it will be returned; otherwise a temporary scope will be used to create the handler and execute it; and the returned value will be stored.
If simultaneous requests are made while the handler is executing, they will wait for the first handler to complete, rather than executing the handler a second/simultaenous time.
Removing Data From the Cache
Using an instance of the GetValueCache class that you have created above, you can remove cached data by calling:
await cache.RemoveValue(request);
If a handler is running based on this request, it will be cancelled, and any callers waiting on the results from
this handler will experience a CancellationToken cancellation.
Updating Data In the Cache
Using an instance of the GetValueCache class that you have created above, you can assign cached data by calling:
await cache.SetValue(request, response);
If a handler is running based on this request, it will be cancelled, and any callers waiting on the results from this handler will immediately receive the updated response.
| 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- Immediate.Handlers (>= 3.8.0)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.8)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.8)
-
net11.0
- Immediate.Handlers (>= 3.8.0)
-
net8.0
- Immediate.Handlers (>= 3.8.0)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
-
net9.0
- Immediate.Handlers (>= 3.8.0)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.16)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.16)
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 |
|---|---|---|
| 2.0.2 | 41 | 6/4/2026 |
| 2.0.1 | 45 | 6/4/2026 |
| 2.0.0 | 45 | 6/3/2026 |
| 1.2.0 | 454 | 2/10/2026 |
| 1.1.0 | 117 | 2/9/2026 |
| 1.0.0 | 1,808 | 4/22/2025 |
| 0.1.0-preview.7 | 472 | 2/17/2025 |
| 0.1.0-preview.6 | 503 | 1/10/2025 |
| 0.1.0-preview.5 | 183 | 1/1/2025 |
| 0.1.0-preview.4 | 165 | 1/1/2025 |
| 0.1.0-preview.3 | 167 | 12/21/2024 |
| 0.1.0-preview.2 | 200 | 11/13/2024 |
| 0.1.0-preview | 204 | 11/13/2024 |