Carter.Cache.Redis 0.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Carter.Cache.Redis --version 0.1.1                
NuGet\Install-Package Carter.Cache.Redis -Version 0.1.1                
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="Carter.Cache.Redis" Version="0.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Carter.Cache.Redis --version 0.1.1                
#r "nuget: Carter.Cache.Redis, 0.1.1"                
#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.
// Install Carter.Cache.Redis as a Cake Addin
#addin nuget:?package=Carter.Cache.Redis&version=0.1.1

// Install Carter.Cache.Redis as a Cake Tool
#tool nuget:?package=Carter.Cache.Redis&version=0.1.1                

Carter.Cache Mit License

An extensible library to cache your Carter modules.

Builds

Github Branch Coverage
.NET master CodeCov

Packages

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

Installation

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));
builder.Services.AddCarter();
  1. Define a Configuration usage
var app = builder.Build();

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

app.UseCarterCaching();
app.MapCarter();

app.Run();

  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.

Customization

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("127.0.0.1:6379"));
builder.Services.AddSingleton(provider => new CachingOption()
{
    Store = provider.GetRequiredService<ICacheStore>()
});

IServiceProvider serviceProvider = builder.Services.BuildServiceProvider();

builder.Services.AddCarterCaching(serviceProvider.GetRequiredService<CachingOption>());
builder.Services.AddCarter();

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("127.0.0.1", 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
services.AddCarterCaching(serviceProvider.GetRequiredService<CachingOption>());

For more information check the samples included.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
0.2.0 189 9/7/2023
0.1.1 288 1/28/2023
0.1.0 316 1/9/2023
0.0.8 297 12/31/2021
0.0.7 350 11/3/2021
0.0.6 391 9/11/2021
0.0.5 360 6/30/2021