MitMediator.InMemoryCache 9.0.0-alfa

This is a prerelease version of MitMediator.InMemoryCache.
There is a newer prerelease version of this package available.
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
                    
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="MitMediator.InMemoryCache" Version="9.0.0-alfa" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MitMediator.InMemoryCache" Version="9.0.0-alfa" />
                    
Directory.Packages.props
<PackageReference Include="MitMediator.InMemoryCache" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MitMediator.InMemoryCache --version 9.0.0-alfa
                    
#r "nuget: MitMediator.InMemoryCache, 9.0.0-alfa"
                    
#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.
#:package MitMediator.InMemoryCache@9.0.0-alfa
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MitMediator.InMemoryCache&version=9.0.0-alfa&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=MitMediator.InMemoryCache&version=9.0.0-alfa&prerelease
                    
Install as a Cake Tool

MitMediator.InMemoryCache

An attribute-driven in-memory caching extension for the MitMediator

Build and Test NuGet .NET 9.0 NuGet Downloads License

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 is response.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 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. 
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
9.0.0-alfa-2 48 9/13/2025
9.0.0-alfa 60 9/12/2025

v9.0.0-alfa
Init