Franz.Common.Caching 2.0.1

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

Here’s an updated README for version 1.7.8, including all the observability improvements, metrics observer, logging + metrics observer, and Excel/export-ready observer you’ve just implemented:


Franz.Common.Caching

A full-featured caching module for the Franz Framework. Provides unified cache abstractions, hybrid caching (L1 + L2), Mediator request caching, settings cache, and first-class observability via Serilog, OpenTelemetry, and custom metrics/log observers.


  • Current Version: 2.0.1
  • Target Framework: .NET 10.0

✨ Features

  • 🧱 Unified abstractions

    • ICacheProvider
    • ICacheKeyStrategy
    • ISettingsCache
    • Single cache options model (TTL, sliding, priority, tags)
  • ⚑ Hybrid caching support

    • L1: In-memory (fast, local)
    • L2: Distributed / Redis (durable, shared)
    • Read-through + write-through behavior
    • Optional local cache hinting
  • 🧩 Pluggable providers

    • MemoryCacheProvider
    • DistributedCacheProvider
    • RedisCacheProvider
  • πŸ”‘ Flexible cache key strategies

    • Default (type + normalized payload)
    • Namespaced (domain separation)
    • Custom strategies (drop-in)
  • πŸ” Mediator pipeline integration

    • Automatic cache HIT / MISS detection
    • Transparent response caching
    • Per-request cache options (TTL, sliding, bypass)
    • CQRS-aware (queries cached, commands skipped)
    • Null response caching supported
  • πŸ“ˆ Observability out of the box

    • Serilog enrichment

      • FranzCorrelationId
      • FranzCacheKey
      • FranzCacheHit
    • OpenTelemetry metrics

      • cache hits / misses
      • lookup latency
    • OpenTelemetry trace tags

      • franz.cache.*
    • Observers

      • MetricsCacheObserver – in-memory metrics, hits, sets, total cache weight
      • LoggingMetricsObserver – combines Serilog logging + metrics
      • ExcelCacheObserver – export cache statistics (hits, misses, size) to Excel

πŸ”Œ Plug-and-play DI extensions

  • AddFranzMemoryCaching()
  • AddFranzDistributedCaching<T>()
  • AddFranzRedisCaching()
  • AddFranzHybridCaching()
  • AddFranzMediatorCaching()
  • AddObservableCaching() – enables any combination of observers
  • AddLoggingCacheObserver()
  • AddMetricsCacheObserver()
  • AddLoggingMetricsObserver()
  • AddExcelCacheObserver() – opt-in for Excel exports

Observers are opt-in. You can register any combination depending on telemetry/logging needs.


πŸ“¦ Installation

dotnet add package Franz.Common.Caching --version 1.7.8

πŸš€ Quickstart

// Program.cs
builder.Services.AddFranzHybridCaching();

// Mediator caching
builder.Services.AddFranzMediatorCaching(opts =>
{
    opts.DefaultTtl = TimeSpan.FromMinutes(10);
    opts.ShouldCache = req => !req.GetType().Name.EndsWith("Command");
});

// Observers
builder.Services.AddObservableCaching()
    .AddLoggingCacheObserver()
    .AddMetricsCacheObserver()
    .AddLoggingMetricsObserver()
    .AddExcelCacheObserver(); // optional Excel export

πŸ“Š Observability Examples

Metrics Observer

Tracks per-key stats:

  • Hits / Misses
  • Last access / set time
  • Estimated size in bytes
  • Total cache weight
var snapshot = metricsObserver.Snapshot();
var totalWeight = snapshot.Values.Sum(x => x.EstimatedSizeBytes);

Logging + Metrics Observer

Combines Serilog logs + OpenTelemetry metrics:

{
  "FranzCorrelationId": "af42c6...",
  "FranzPipeline": "CachingPipeline",
  "FranzCacheKey": "GetUserById:{\"Id\":42}",
  "FranzCacheHit": true,
  "Message": "Cache HIT for GetUserByIdQuery in 0.6ms"
}

Excel Observer

Exports relevant stats only (hits/misses/size) to Excel for offline analysis.


πŸ“ Changelog

v2.0.1 – Internal Modernization

  • Messaging and infrastructure refactored for async, thread-safety, and modern .NET 10 patterns.
  • All APIs remain fully backward compatible.
  • Tests, listeners, and pipeline components modernized.

1.7.8

  • Added MetricsCacheObserver – in-memory hit/miss, per-key stats, total cache weight
  • Added LoggingMetricsObserver – combines Serilog + metrics, tracks hits, sets, latency
  • Added ExcelCacheObserver – export relevant cache stats to Excel
  • Updated DI extensions – opt-in observer registration methods
  • Exposed CurrentKeys property on observers for testability
  • Observers integrated with Redis, Distributed, Memory caches
  • Internal improvements for latency tracking in CacheAccessDescriptor

1.7.7

  • Unified cache options across all providers
  • Hybrid cache provider stabilized (L1 + L2)
  • Removed legacy entry options
  • Provider internals aligned with Mediator pipeline
  • Improved null caching semantics
  • Documentation refresh

1.7.6

  • Lazy infrastructure loading
  • Redis startup stability improvements

1.6.20

  • Upgraded to .NET 10.0

Perfect β€” we can make a small ASCII/flow diagram for the README that’s simple, readable, and shows the cache β†’ observers β†’ outputs flow. Here’s a suggestion you can drop right under the Observability section:

Cache Operation Flow
-------------------

        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚ ICacheProviderβ”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚ OnCacheSet / OnCacheHit / OnCacheRemove
                β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚ ObservableCacheProvider β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚
      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
      β–Ό         β–Ό         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Logging   β”‚ β”‚ Metrics      β”‚ β”‚ Excel Export  β”‚
β”‚ Observer  β”‚ β”‚ Observer     β”‚ β”‚ Observer      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  • ICacheProvider β†’ executes cache operations (set, get, remove).

  • ObservableCacheProvider β†’ wraps the cache provider and broadcasts to all registered observers.

  • Observers can be:

    • LoggingCacheObserver β†’ Serilog / log enrichment
    • MetricsCacheObserver β†’ in-memory stats, hits, misses, cache weight
    • LoggingMetricsObserver β†’ combined logs + metrics
    • ExcelCacheObserver β†’ exports relevant stats to Excel

This makes it instantly clear how any cache action flows through the system and where the data ends up.

If you want, I can also make a slightly fancier Markdown/mermaid diagram that will render nicely on GitHub and looks professional in the README. Do you want me to do that too?

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

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.0.2 59 3/30/2026
2.0.1 81 3/29/2026
1.7.8 90 3/2/2026
1.7.7 107 1/31/2026
1.7.6 97 1/22/2026
1.7.5 103 1/10/2026
1.7.4 122 12/27/2025
1.7.3 186 12/22/2025
1.7.2 186 12/21/2025
1.7.1 129 12/20/2025
1.7.0 293 12/16/2025
1.6.21 204 11/27/2025
1.6.19 168 10/25/2025
1.6.15 197 10/20/2025
1.6.14 197 10/15/2025
1.6.3 201 10/9/2025
1.6.2 203 10/7/2025
1.5.9 203 9/24/2025
1.5.4 245 9/23/2025
1.5.3 252 9/21/2025
Loading failed