Carter.Cache 0.0.8

.NET Standard 2.0
Install-Package Carter.Cache -Version 0.0.8
dotnet add package Carter.Cache --version 0.0.8
<PackageReference Include="Carter.Cache" Version="0.0.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Carter.Cache --version 0.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Carter.Cache, 0.0.8"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Carter.Cache as a Cake Addin
#addin nuget:?package=Carter.Cache&version=0.0.8

// Install Carter.Cache as a Cake Tool
#tool nuget:?package=Carter.Cache&version=0.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Carter.Cache Mit License

An extensible library to cache your Carter modules.


Github Branch Coverage
.NET master CodeCov


Package NuGet (Stable) MyGet (Prerelease)
Carter.Cache NuGet MyGet
Carter.Cache.Memcached NuGet MyGet
Carter.Cache.Redis NuGet MyGet


Install via nuget

PM> Install-Package Carter.Cache

This library depends on Carter to properly work, you can install Carter using the following command:

PM> Install-Package Carter

Sample usage

  1. Add carter caching to your Program.cs:
var builder = WebApplication.CreateBuilder(args);

//The rest of your Program.cs configuration ....

//It is recommended to always provide a caching max size limit
builder.Services.AddCarterCaching(new CachingOption(2048));
  1. Define a Configuration usage
var app = builder.Build();

//The rest of your configuration usage ....

app.UseEndpoints(builder => builder.MapCarter());


  1. Add the Cacheable clause to your module:
    public class HomeModule : ICarterModule
        public void AddRoutes(IEndpointRouteBuilder app)
            app.MapGet("/", (HttpContext ctx) =>
                ctx.AsCacheable(10); //In Seconds

                ctx.Response.StatusCode = 200;
                return ctx.Response.WriteAsync("Hello world");

The default configuration does use the Microsoft.Extensions.Caching.Memory library as a default caching mechanism. Note: By default memory caching can put lots of pressure on the memory of your system, please refer to the following microsoft in-memory cache docs for basics on usage.


You can easily define a custom Store by implementing the ICacheStore interface with the following signature:

    public interface ICacheStore
        bool TryGetValue(string key, out CachedResponse cachedResponse);

        void Set(string key, CachedResponse response, TimeSpan expiration);

        void Remove(string key);

Also a custom Key can be easily defined by implementing the ICacheKey interface:

    public interface ICacheKey
        string Get(HttpRequest request);

Redis store

A redis store which includes the dependency on StackExchange.Redis and can be used as a replacement of the memory store.

Firstly, install the library using .net cli dotnet add package Carter.Cache.Redis or using Package Manager Install-Package Carter.Cache.Redis. The usage requires the following configurations on the Startup.cs file:

//The rest of your Program.cs ....

builder.Services.AddSingleton<ICacheStore>(new RedisStore(""));
builder.Services.AddSingleton(provider => new CachingOption()
    Store = provider.GetRequiredService<ICacheStore>()

IServiceProvider serviceProvider = builder.Services.BuildServiceProvider();


Memcached store

Alternatively, a memcached store can also be included as an alternatively, using a dependency on the library EnyimMemcachedCore.

To install, using .net cli dotnet add package Carter.Cache.Memcached or using Package Manager Install-Package Carter.Cache.Memcached. The usage requires the following reconfigurations on the ConfigureServices method of Startup:

//The rest of your Program.cs ....

//Point to the server / port desired
builder.Services.AddEnyimMemcached(options => options.AddServer("", 11211));

//Resolve the IMemcachedClient dependency using EnyimMemcached
builder.Services.AddSingleton<ICacheStore>(provider => new MemcachedStore(provider.GetRequiredService<IMemcachedClient>()));

//Define Caching options using the store configured
builder.Services.AddSingleton(provider => new CachingOption()
    Store = provider.GetRequiredService<ICacheStore>() 

IServiceProvider serviceProvider = services.BuildServiceProvider();

//Pass it as a dependency to the add

For more information check the samples included.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Carter.Cache:

Package Downloads

Package Description


Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.8 329 12/31/2021
0.0.7 283 11/3/2021
0.0.6 302 9/11/2021
0.0.5 339 6/10/2021
0.0.4 482 9/15/2020
0.0.3 223 9/10/2020
0.0.2 444 6/26/2020

Release targeting dotnet 6