Innovabit.DotNet.Interceptors.Caching.Abstractions 3.0.129

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

Innovabit.DotNet.Interceptors.Caching.Abstractions

Method-result caching for Innovabit.DotNet.Interceptors via a [Cache] attribute. This is the provider-agnostic base: it ships the interceptor, the attribute, the pluggable key generator/serializer and the ICacheStore abstraction. Pick a store provider to actually cache anything:

  • Innovabit.DotNet.Interceptors.Caching.Memory — in-process cache on .NET's IMemoryCache.
  • Innovabit.DotNet.Interceptors.Caching.Redis — distributed cache on Redis (IDistributedCache).

Usage

services
    .AddInterceptors()
    .AddInMemoryCache()                       // or .AddRedisCache(o => o.Configuration = "localhost:6379")
    .ConfigureCacheDefaults(d => d.DurationSeconds = 60);   // optional global defaults

services.AddScopedWithInterception<IPriceService, PriceService>();
public class PriceService : IPriceService
{
    // Cached for 30s; a bare [Cache] would inherit the configured defaults.
    [Cache(DurationSeconds = 30)]
    public Task<decimal> GetQuoteAsync(string symbol) => _api.FetchAsync(symbol);
}

The first call runs the method and stores the result; later calls with the same arguments return the cached value without invoking the method. Only value-returning methods are cached — void, Task and ValueTask (no result) are ignored; Task<T>/ValueTask<T> are cached on their unwrapped result.

[Cache] / CacheDefaults

Property Meaning
DurationSeconds Absolute lifetime in seconds. 0 = no absolute expiration.
SlidingExpirationSeconds Expire after this long without a read. 0 = disabled.
KeyPrefix Prefix prepended to the generated key (namespacing per tenant/version/…).
CacheNullValues Whether a null result is cached. Defaults to false.

Any property left unset on [Cache] inherits from the CacheDefaults configured via ConfigureCacheDefaults; a property set on the method always wins.

Cache keys

The key is derived per method + argument values, so calls with different arguments are cached separately and calls with the same arguments share an entry. The default ICacheKeyGenerator hashes the method signature and the arguments' public state (SHA-256).

Values are read by their runtime type — properties and public fields, nested and derived values included — so two different values never share an entry because of how they were declared. [JsonIgnore] members are left out, and a nested CancellationToken too. A value with no readable state (a class with only private fields, say) is identified by its ToString() when its type overrides it; otherwise, and always for a Stream, a delegate or a Task, the call fails with an InvalidOperationException naming the parameter. Mark that parameter [CacheKeyIgnore] if it does not affect the result, or pass the values that do.

Two kinds of parameter are left out of the key:

  • CancellationToken parameters — always ignored (runtime plumbing, not part of a call's identity).
  • Parameters marked [CacheKeyIgnore] — opt a specific parameter out of the key when it does not affect the result (a logger, a correlation id, an IProgress<T> callback, …).
// requestId does not change the result, so both calls hit the same cache entry:
[Cache(DurationSeconds = 30)]
public Task<Quote> GetQuoteAsync(string symbol, [CacheKeyIgnore] Guid requestId) => _api.FetchAsync(symbol);

[CacheKeyIgnore] is honoured by the default key generator; a custom generator defines its own policy. Like other parameter-level attributes it only has an effect while the method is intercepted (also carries [Cache]) — the bundled analyzer warns (INTX002) when it does not.

When the store fails

A store that throws — Redis is down, an entry no longer deserializes — is treated as a miss: the method runs and its result is returned. Watch for it, or opt out of it, through the defaults:

services.AddInterceptors()
    .AddRedisCache(...)
    .ConfigureCacheDefaults(o =>
    {
        o.OnStoreFailure = (key, exception) => logger.LogWarning(exception, "Cache store failed.");
        o.ThrowOnStoreFailure = false; // the default; true fails the call instead
    });

After a failed read the result is not written either, so an outage costs one store timeout per call rather than two; an entry that could not be deserialized is rewritten.

Flexibility / extension points

Everything is resolved from DI and can be swapped:

  • ICacheStore — the backing store. Provided by the Memory/Redis packages; implement your own for any backend.
  • ICacheKeyGenerator — how keys are derived. Default: SHA-256 over the method signature + the arguments' public state (ignoring CancellationToken and [CacheKeyIgnore] parameters). Replace with UseCacheKeyGenerator<T>().
  • ICacheSerializer — how values are serialized for distributed stores. Default: System.Text.Json. Replace with UseCacheSerializer<T>().

Pipeline order

CacheInterceptor runs at InterceptorOrders.Caching (200) — above retry/timeout so a hit short-circuits the expensive work, below validation so invalid arguments still fail fast. Override per registration with .Register<CacheInterceptor>(order) / .SetOrder<CacheInterceptor>(order).

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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Innovabit.DotNet.Interceptors.Caching.Abstractions:

Package Downloads
Innovabit.DotNet.Interceptors.Caching.Memory

In-memory (IMemoryCache) store provider for interceptor-based caching.

Innovabit.DotNet.Interceptors.Caching.Redis

Redis (IDistributedCache) store provider for interceptor-based caching.

Innovabit.DotNet.Interceptors.All

Meta-package: every interceptor concern in the suite (logging, validation, caching, notifications, telemetry, audit, authorization, rate limiting, coordination, feature gates, transactions, retry/timeout/circuit breaker/fallback) in one reference. Providers are separate packages — pick the ones you use.

Innovabit.DotNet.Interceptors.Caching.Hybrid

HybridCache (L1 + L2, with stampede protection) store provider for interceptor-based caching.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.136 58 12/5/2026
3.0.135 242 11/30/2026
3.0.134 137 11/30/2026
3.0.133 138 11/30/2026
3.0.132 132 11/30/2026
3.0.129 150 11/30/2026
3.0.128 140 11/30/2026
3.0.127 158 11/30/2026
3.0.126 146 11/30/2026
3.0.125 142 11/30/2026
3.0.124 161 11/28/2026
3.0.123 141 11/28/2026
3.0.122 273 11/21/2026
2.0.121 180 11/21/2026
2.0.120 169 11/21/2026
2.0.119 230 11/14/2026
2.0.118 190 11/7/2026
2.0.117 200 10/31/2026
2.0.116 182 10/26/2026
2.0.115 194 10/17/2026
Loading failed