FGutierrez.Core.DistributedCache 1.1.2

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

⚡ FGutierrez.Core.DistributedCache

NuGet Downloads License .NET Storage OpenTelemetry


🚀 Overview

FGutierrez.Core.DistributedCache is a high-performance distributed caching library for .NET 8 designed to provide a unified abstraction over multiple cache providers.

The library simplifies cache integration by providing:

  • In-memory caching
  • Redis distributed caching
  • Automatic resilience and fallback strategies
  • HTTP response caching middleware
  • OpenTelemetry metrics
  • Health checks
  • Provider-based extensibility

Built following a cloud-native approach, the library allows applications to consume caching capabilities without being coupled to a specific infrastructure provider.


✨ Key Features

Feature Description
🧩 Unified API Single abstraction for multiple cache providers
⚡ High Performance Optimized cache access patterns
🔄 Resilience Automatic fallback when distributed cache is unavailable
🧠 Cache Aside Pattern Built-in GetOrAddAsync workflow
🌐 HTTP Middleware Response caching support for APIs
📊 Observability OpenTelemetry metrics integration
🩺 Health Checks Cache provider availability monitoring

🏗 Architecture

graph TD

    App[Application] --> Cache[ICoreCacheService]

    Cache --> Decorator[Resilient Cache Decorator]

    Decorator --> Redis[RedisCacheStorage]
    Decorator --> Memory[MemoryCacheStorage]

    Redis --> RedisServer[(Redis Server)]
    Memory --> Runtime[(Application Memory)]

🛡️ Resilience Flow

flowchart TD

    Request([Cache Request])

    Request --> RedisCheck{Redis Available?}

    RedisCheck -- Yes --> RedisAccess[Attempt Redis Access]

    RedisAccess --> Success{Operation Successful?}

    Success -- Yes --> Return([Return Cached Data])

    Success -- No --> Fallback[Log Error + Use Memory Cache]

    RedisCheck -- No --> Fallback

    Fallback --> MemoryAccess[Query Memory Cache]

    MemoryAccess --> Return

⚡ GetOrAddAsync Cache-Aside Pattern

sequenceDiagram

    participant App as Application
    participant Cache as ICoreCacheService
    participant DB as Data Source

    App->>Cache: GetOrAddAsync(key, factory)

    Cache->>Cache: Check cache entry

    alt Cache Hit

        Cache-->>App: Return cached value

    else Cache Miss

        Cache->>DB: Execute factory()

        DB-->>Cache: Return data

        Cache->>Cache: Store value

        Cache-->>App: Return new value

    end

🌐 HTTP Cache Middleware Lifecycle

sequenceDiagram

    participant Client as HTTP Client
    participant MW as Cache Middleware
    participant API as API Endpoint

    Client->>MW: GET /api/resource

    MW->>MW: Check cache

    alt Cache Hit

        MW-->>Client: Cached Response

    else Cache Miss

        MW->>API: Execute Request

        API-->>MW: Response

        MW->>MW: Store Response

        MW-->>Client: Original Response

    end

📦 Installation

dotnet add package FGutierrez.Core.DistributedCache

⚙️ Configuration

Redis Enabled

builder.Services.AddCoreDistributedCache(options =>
{
    options.InstanceName = "MyApplication";

    options.DefaultExpiration = TimeSpan.FromMinutes(30);

    options.Redis.Enabled = true;

    options.Redis.Configuration = redis =>
    {
        redis.EndPoints.Add("localhost", 6379);
        redis.AbortOnConnectFail = false;
    };
});

🧑‍💻 Usage Example

public class ProductService
{
    private readonly ICoreCacheService _cache;

    public ProductService(ICoreCacheService cache)
    {
        _cache = cache;
    }


    public async Task<Product> GetAsync(Guid id)
    {
        return await _cache.GetOrAddAsync(
            $"product:{id}",
            async () =>
            {
                return await LoadFromDatabase(id);
            });
    }
}

📊 Observability

The library exposes cache metrics through OpenTelemetry.

Metric Description
cache.distributed.hits Successful cache retrievals
cache.distributed.misses Cache lookup failures
cache.distributed.errors Provider errors
cache.distributed.fallbacks Resilience fallback executions

Compatible with any OpenTelemetry backend:

  • Grafana
  • Prometheus
  • Jaeger
  • Azure Monitor
  • Elastic Observability
  • Other OTLP-compatible platforms

🩺 Health Checks

The library integrates with:

builder.Services.AddHealthChecks();

Allowing monitoring of:

  • Redis availability
  • Memory cache status
  • Provider connectivity

🛠️ Requirements

  • .NET 8 SDK
  • Microsoft.Extensions.Caching.Memory
  • StackExchange.Redis
  • OpenTelemetry
  • Microsoft.Extensions.Diagnostics.HealthChecks

🏗 Design Principles

FGutierrez.Core.DistributedCache follows:

  • Clean Architecture principles
  • Provider-based extensibility
  • High cohesion / low coupling
  • Cloud-native design
  • Resilient infrastructure patterns
  • Observability-first development

📌 Roadmap

  • Memory Cache provider
  • Redis provider
  • Cache Aside pattern
  • Resilience fallback
  • OpenTelemetry metrics
  • Health checks

Future:

  • SQL Server cache provider
  • PostgreSQL cache provider
  • Multi-level distributed cache
  • Cache invalidation events

🤝 Contributing

Contributions are welcome.

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Open a Pull Request

📄 License

MIT License © Federin Pastor Gutierrez Ortiz

See the LICENSE file for details.


⭐ Support

If this ecosystem helps you, consider giving the repository a star on GitHub.

Building modern .NET distributed systems, one reusable component at a time.

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 was computed.  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
1.1.6 99 6/25/2026
1.1.5 99 6/23/2026
1.1.4 95 6/22/2026
1.1.3 95 6/22/2026
1.1.2 101 6/19/2026