RetailSolutions.Shared.Cache 1.3.1400

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

RetailSolutions.Shared.Cache

Unified caching abstraction for .NET 10 applications with support for Redis and In-Memory backends, automatic environment detection, and distributed locks via RedLock.net.

Installation

dotnet add package RetailSolutions.Shared.Cache

Or via Package Manager Console:

Install-Package RetailSolutions.Shared.Cache

Requirements

  • .NET 10.0+
  • Redis instance (only required when using Redis backend)

Quick Start

Register the cache service in your application startup:

var builder = WebApplication.CreateBuilder(args);

var cacheSettings = builder.Configuration.GetSection("Cache").Get<CacheSettings>()
    ?? new CacheSettings();

builder.Services.AddCache(cacheSettings);

var app = builder.Build();
app.UseCache(); // validates Redis connectivity before startup

app.Run();

Inject ICacheService wherever caching is needed:

public class ProductService(ICacheService cache)
{
    public async Task<Product> GetProductAsync(string id) =>
        await cache.GetOrSetAsync(
            $"product:{id}",
            () => repository.GetByIdAsync(id),
            TimeSpan.FromMinutes(30)
        );
}

Configuration

appsettings.json

{
  "Cache": {
    "CacheType": "Auto",
    "Redis": {
      "ConnectionString": "localhost:6379",
      "InstanceName": "myapp"
    },
    "Memory": {
      "SizeLimit": 10240,
      "DefaultExpiration": "00:30:00"
    },
    "Expirations": [
      { "Key": "product:*", "Expiration": "01:00:00" },
      { "Key": "session:*", "Expiration": "00:15:00" }
    ]
  }
}
CacheType Behavior
Auto (default) Detects environment automatically
Redis Forces Redis backend
Memory Forces In-Memory backend

Environment Detection (Auto mode)

Environment Selected Backend
Kubernetes + Redis available Redis
IIS Memory Cache
Other Memory Cache

If Redis is configured but unreachable, the library automatically falls back to Memory Cache.

ICacheService API

Method Description
GetAsync<T>(key) Retrieve a cached value
SetAsync<T>(key, value, expiration?) Store a value with optional TTL
RemoveAsync(key) Remove a specific cache entry
ExistsAsync(key) Check if a key exists
GetOrSetAsync<T>(key, factory, expiration?) Get or compute and cache
RemoveByPatternAsync(pattern) Bulk-remove entries matching a regex pattern

Startup Validation

UseCache() performs a write/read/delete health check against Redis before the application starts. It throws if the check fails, preventing startup with a broken cache connection. Ignored when using Memory Cache.

app.UseCache(); // throws on Redis connectivity failure

Distributed Locks

Register RedLock.net support separately:

builder.AddRedisLock(
    builder.Configuration.GetConnectionString("Redis"),
    "my-application-name"
);

Use IDistributedLockFactory to acquire distributed locks:

public class OrderService(IDistributedLockFactory lockFactory)
{
    public async Task ProcessOrderAsync(string orderId)
    {
        await using var redLock = await lockFactory.CreateLockAsync(
            $"order:{orderId}",
            expiryTime: TimeSpan.FromSeconds(30)
        );

        if (!redLock.IsAcquired)
            throw new InvalidOperationException("Order is already being processed.");

        await ProcessAsync(orderId);
    }
}

Dependencies

Package Version
Microsoft.Extensions.Configuration 10.0.1
Microsoft.Extensions.DependencyInjection 10.0.1
Microsoft.Extensions.Hosting 10.0.1
Microsoft.Extensions.Caching.Memory 10.0.1
StackExchange.Redis 2.9.25
RedLock.net 2.3.2
Serilog 4.1.0

License

Copyright © Retail Solutions

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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 RetailSolutions.Shared.Cache:

Package Downloads
RetailSolutions.Shared.Jobs

Controle de execução de cronjobs

RetailSolutions.Shared.Max

Abstrações da Max Sistemas

RetailSolutions.Shared.Ifood

Abstrações do Ifood

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.1400 159 7/7/2026
1.3.1370 109 7/6/2026
1.2.122 127 7/6/2026
1.2.107 104 4/30/2026
1.2.90 666 12/13/2025
1.2.89 199 12/13/2025
1.2.84 196 12/13/2025
1.2.73 250 12/12/2025
1.2.70 154 12/12/2025