MitMediator.InMemoryCache
9.0.0-alfa
See the version list below for details.
dotnet add package MitMediator.InMemoryCache --version 9.0.0-alfa
NuGet\Install-Package MitMediator.InMemoryCache -Version 9.0.0-alfa
<PackageReference Include="MitMediator.InMemoryCache" Version="9.0.0-alfa" />
<PackageVersion Include="MitMediator.InMemoryCache" Version="9.0.0-alfa" />
<PackageReference Include="MitMediator.InMemoryCache" />
paket add MitMediator.InMemoryCache --version 9.0.0-alfa
#r "nuget: MitMediator.InMemoryCache, 9.0.0-alfa"
#:package MitMediator.InMemoryCache@9.0.0-alfa
#addin nuget:?package=MitMediator.InMemoryCache&version=9.0.0-alfa&prerelease
#tool nuget:?package=MitMediator.InMemoryCache&version=9.0.0-alfa&prerelease
MitMediator.InMemoryCache
An attribute-driven in-memory caching extension for the MitMediator
Installation
1. Install the package
dotnet add package MitMediator.InMemoryCache -v 9.0.0
2. Use extension for IServiceCollection
// Register handlers and IMediator
builder.Services.AddMitMediator();
// Register MemoryCache and InMemoryCacheBehavior
// Read information about all IRequest<>
builder.Services.AddRequestsInMemoryCache()
⚠️⚠️⚠️ Make sure to register .AddRequestsInMemoryCache()
as the last IPipelineBehavior
. Cached responses will prevent further pipeline execution
To customize MemoryCache
options and specify assemblies to scan:
builder.Services.AddRequestsInMemoryCache(
new MemoryCacheOptions { SizeLimit = 1000 },
new []{typeof(GetQuery).Assembly});`
For
ICollection
types, the cache entry size isresponse.Count
; for all other types, it is 1
Usage
Decorate your request classes with caching attributes:
using MitMediator.InMemoryCache;
[CacheForever]
public struct GetGenresQuery : IRequest<Genre[]>;
[CacheForSeconds(10)]
public struct GetBookQuery : IRequest<Book>
{
public int BookId { get; set; }
}
[CacheUntilSent(typeof(DeleteAuthorCommand), typeof(UpdateAuthorCommand))]
public struct GetAuthorQuery : IRequest<Author>
{
public int AuthorId { get; init; }
}
Available Attributes
[CacheForever]
- caches the response indefinitely[CacheForSeconds(int seconds)]
- caches the response for the specified seconds[CacheUntilSent(params Type[] triggers)]
- caches the response until one of the specified request types is sent
Responses are cached per unique request data.
For example, GetAuthorQuery will cache a separate response for each AuthorId
See samples
License
MIT
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 was computed. 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. |
-
net9.0
- Microsoft.Extensions.Caching.Memory (>= 9.0.0)
- MitMediator (>= 9.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.
Version | Downloads | Last Updated |
---|---|---|
9.0.0-alfa-2 | 48 | 9/13/2025 |
9.0.0-alfa | 60 | 9/12/2025 |
v9.0.0-alfa
Init