Spincity.RedisCache 9.0.2

dotnet add package Spincity.RedisCache --version 9.0.2
                    
NuGet\Install-Package Spincity.RedisCache -Version 9.0.2
                    
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="Spincity.RedisCache" Version="9.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Spincity.RedisCache" Version="9.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Spincity.RedisCache" />
                    
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 Spincity.RedisCache --version 9.0.2
                    
#r "nuget: Spincity.RedisCache, 9.0.2"
                    
#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 Spincity.RedisCache@9.0.2
                    
#: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=Spincity.RedisCache&version=9.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Spincity.RedisCache&version=9.0.2
                    
Install as a Cake Tool

Spincity Redis Cache

Spincity.RedisCache contains an implementation for caching, retrieving and removing keys from a Redis database.

Register the Redis Cache in the Startup.cs file of your project as shown below:
public void ConfigureServices(IServiceCollection services)
    {
        services.AddRedisCache(options =>
                {
                
                    options.RegisterInstance(new MultiplexerCacheOptions()
                    {
                        ConfigurationOptions = new ConfigurationOptions()
                        {
                            EndPoints =
                            {
                                Configuration.GetConnectionString("RedisMultiplexerCacheConnection") ?? string.Empty
                            },
                            AllowAdmin = true
                        },
                        DatabaseIndex = 0
                    });
                    

                    options.DistributedCacheOptions = new RedisCacheOptions()
                    {
                        Configuration = Configuration.GetConnectionString("RedisDistributedCacheConnection"),
                        InstanceName = platform,
                    };
                });  
        ...
    }

options.RegisterInstance is used to register the Redis Multiplexer Cache. The ConfigurationOptions is used to set the Redis connection string and the DatabaseIndex is used to set the database index.

options.DistributedCacheOptions is used to register the Redis Distributed Cache. The Configuration is used to set the Redis connection string and the InstanceName is used to set the instance name.

How to use (with examples)

private readonly ICacheDistributedService _cacheDistributedService;
private readonly ICacheMultiplexerService _cacheMultiplexerService;

public YourService(ICacheDistributedService cacheDistributedService, ICacheMultiplexerService cacheMultiplexerService)
{
    _cacheDistributedService = cacheDistributedService;
    _cacheMultiplexerService = cacheMultiplexerService;
}

public async Task<string> GetCacheValueMultiplexer(string key)
{
     await _cacheMultiplexerService.GetHashAsync<BetCacheData>("key", databaseIndex: 0);

}

public async Task SetCacheValueMultiplexer(string key, string value)
{
    await _cacheMultiplexerService.SetHashAsync("key", new SomeObject() { Value1 = "value1" },TimeSpan.FromDays(7),  databaseIndex: 0);
    await _cacheMultiplexerService.SetStringAsync("key", "somestring", TimeSpan.FromDays(7),  databaseIndex: 0);
}

public async Task GetSetValueDistributedCache(string key)
{
    await _cacheService.GetDataAsync<GetGamesResult>("key", () =>  SomeMethod(), new string[] {  }, TimeSpan.FromHours(2));
}

...
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 (3)

Showing the top 3 NuGet packages that depend on Spincity.RedisCache:

Package Downloads
Spincity.Tools

Helper to be used with Spincity.RedisCache package

Spincity.RedisCache.Helpers

Helper to be used with Spincity.RedisCache package

Spincity.IdempotentRequestHandler

Idempotent Request Handler customized for Spincity Solutions

GitHub repositories

This package is not used by any popular GitHub repositories.

Add new method HasKeyAsync to check if a key exists in the cache