StackExchangeRedisCache.Contrib 2.1008.20016

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

// Install StackExchangeRedisCache.Contrib as a Cake Tool
#tool nuget:?package=StackExchangeRedisCache.Contrib&version=2.1008.20016                

StackExchangeRedisCache.Contrib

Overview

Provides additional functionality pertaining to Microsoft.Extensions.Caching.StackExchangeRedis (the Redis-backed implementation of IDistributedCache using the StackExchange.Redis client).

Redis Command Flags

What?

Library users may implement ICommandFlagsTweaker to modify the Redis CommandFlags used with certain Redis commands during cache operations.

Why?

This library facilitates scenarios such as:

  • Using a read replica for read commands (CommandFlags.PreferReplica)
  • Using Fire-and-Forget mode for write commands (CommandFlags.FireAndForget)

How?

This library provides an overload of the AddStackExchangeRedisCache extension method that accepts an additional argument of type ICommandFlagsTweaker. To use it, write an implementation of ICommandFlagsTweaker, and supply an instance of your implementation to the provided extension method (instead of calling the base AddStackExchangeRedisCache extension method). NullCommandFlagsTweaker.Instance may be supplied when no tweaking is desired.

public void ConfigureServices(IServiceCollection services)
{
    services.AddStackExchangeRedisCache(rco =>
    {
        rco.ConfigurationOptions = new()
        {
            EndPoints = new()
            {
                "some primary endpoint",
                "some reader (replica) endpoint",
            }
        };

        rco.InstanceName = "some instance name";
    }, MyCommandFlagsTweaker.Instance);
}

private sealed class MyCommandFlagsTweaker : ICommandFlagsTweaker
{
    public static MyCommandFlagsTweaker Instance { get; } = new();

    // set flags for Read commands
    public CommandFlags TweakGetType(CommandFlags flags, RedisKey key) => CommandFlags.PreferReplica;

    // set flags for Write commands
    public CommandFlags TweakSetType(CommandFlags flags, RedisKey key) => CommandFlags.FireAndForget;
}

Sliding Expiration

When getting a value from the cache for which sliding expiration has been set (DistributedCacheEntryOptions.SlidingExpiration), the base library performs two Redis commands. First, the value (and associated entry options) are retrieved. TweakGetType is applicable during this retrieval. Then, a second command is issued to update the expiration. No tweaking is applied during the expiration update. A mechanism to tweak the expiration command may be provided in a future version of this library.

Sliding expiration support when the retrieval command is tweaked to use a replica is somewhat experimental.

Deletion and Refresh

No tweaking is applied during these distributed cache operations. A mechanism to tweak command flags during these operations may be provided in a future version of this library.

Product 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. 
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
2.2008.10016 126 9/27/2024
2.1008.20016 78 9/27/2024
2.1008.10016 98 9/25/2024
2.8.12 94 9/24/2024

repo information