Innovabit.DotNet.Interceptors.Caching.Abstractions 1.0.0.96

dotnet add package Innovabit.DotNet.Interceptors.Caching.Abstractions --version 1.0.0.96
                    
NuGet\Install-Package Innovabit.DotNet.Interceptors.Caching.Abstractions -Version 1.0.0.96
                    
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="1.0.0.96" />
                    
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="1.0.0.96" />
                    
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 1.0.0.96
                    
#r "nuget: Innovabit.DotNet.Interceptors.Caching.Abstractions, 1.0.0.96"
                    
#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@1.0.0.96
                    
#: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=1.0.0.96
                    
Install as a Cake Addin
#tool nuget:?package=Innovabit.DotNet.Interceptors.Caching.Abstractions&version=1.0.0.96
                    
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 JSON-serialized arguments (SHA-256).

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.

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 + JSON-serialized arguments (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 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 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 (2)

Showing the top 2 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.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0.96 116 9/12/2026
1.0.0.95 170 9/5/2026
1.0.0.94 126 9/5/2026
1.0.0.93 127 9/5/2026
1.0.0.90 171 8/17/2026
1.0.0.89 138 8/15/2026
1.0.0.88 135 8/15/2026
1.0.0.87 132 8/13/2026
1.0.0.86 148 8/13/2026