TL.Caching.Helpers 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TL.Caching.Helpers --version 0.2.0
                    
NuGet\Install-Package TL.Caching.Helpers -Version 0.2.0
                    
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="TL.Caching.Helpers" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TL.Caching.Helpers" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="TL.Caching.Helpers" />
                    
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 TL.Caching.Helpers --version 0.2.0
                    
#r "nuget: TL.Caching.Helpers, 0.2.0"
                    
#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 TL.Caching.Helpers@0.2.0
                    
#: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=TL.Caching.Helpers&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=TL.Caching.Helpers&version=0.2.0
                    
Install as a Cake Tool

⚡ TL.Caching.Helpers

NuGet .NET License: MIT

High-performance multilevel caching library for .NET: L1/L2 hybrid cache, RedLock stampede protection, GZip compression, and tenant partitioning.
Biblioteca de caching multinível de alta performance para .NET: cache híbrido L1/L2, proteção contra cache stampede com RedLock, compressão GZip e particionamento por tenant.

O TL.Caching.Helpers disponibiliza uma camada de cache corporativa completa, combinando cache em memória ultrarrápido (L1) com cache distribuído resiliente no Redis (L2). Conta com mecanismos avançados de Distributed Locking (RedLock) para erradicar o problema de Cache Stampede, compressão de tráfego e suporte nativo a isolamento multi-tenant.


📦 Instalação

Adicione o pacote ao seu projeto através do .NET CLI:

dotnet add package TL.Caching.Helpers

🚀 Funcionalidades Principais

Categoria Componentes & Métodos Descrição
Cache Híbrido Multinível IHierarchicalCacheService Consulta em memória (L1); em caso de miss, busca no Redis (L2) e repovoa o L1 de forma transparente.
Proteção Anti-Stampede LockedCacheService Implementação de lock distribuído (Double-Checked Locking) via RedLock, impedindo que milhares de requisições sobrecarreguem o banco ao expirar uma chave.
Compressão de Dados CompressionHelper (GZip) Compactação automática de payloads volumosos antes da gravação no Redis, economizando tráfego de rede e memória.
Particionamento por Regiões region, tenantId Agrupamento lógico de chaves para invalidação em lote e isolamento seguro de múltiplos clientes.
Controle de Vazão AddThrottledCache() Integração fluente com políticas de resiliência e limitação de requisições baseadas em Polly.

💡 Exemplos de Uso

1. Injeção de Dependência no Program.cs

using Caching.Helpers.Extensions;

// Registra Redis distribuído
builder.Services.AddRedisCache(builder.Configuration);

// Registra Cache Hierárquico L1 (Memory) + L2 (Redis)
builder.Services.AddHierarchicalCache(builder.Configuration);

2. Consulta Segura contra Cache Stampede

using Caching.Helpers.Services;

public class CatalogoService
{
    private readonly LockedCacheService _cacheService;

    public CatalogoService(LockedCacheService cacheService)
    {
        _cacheService = cacheService;
    }

    public async Task<List<ProdutoDto>> ObterProdutosDestaqueAsync()
    {
        return await _cacheService.GetOrSetWithLockAsync(
            key: "produtos:destaque",
            factory: async () => await CarregarDoBancoDeDadosAsync(),
            expiration: TimeSpan.FromMinutes(10)
        );
    }

    private static async Task<List<ProdutoDto>> CarregarDoBancoDeDadosAsync()
    {
        await Task.Delay(50);
        return new List<ProdutoDto>
        {
            new("Notebook Corporativo", 4500.00m),
            new("Monitor UltraWide", 1800.00m)
        };
    }
}

public record ProdutoDto(string Nome, decimal Preco);

🏛️ Decisões Arquiteturais e Segurança

Para detalhes sobre locking distribuído, arquitetura de camadas e mitigação de latência:


📄 Licença

Distribuído sob a licença MIT.

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.  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

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.5.0 112 9/27/2026
0.4.0 114 9/23/2026
0.3.0 115 9/18/2026
0.2.0 116 9/12/2026
0.1.0 122 9/7/2026