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
<PackageReference Include="Innovabit.DotNet.Interceptors.Caching.Abstractions" Version="1.0.0.96" />
<PackageVersion Include="Innovabit.DotNet.Interceptors.Caching.Abstractions" Version="1.0.0.96" />
<PackageReference Include="Innovabit.DotNet.Interceptors.Caching.Abstractions" />
paket add Innovabit.DotNet.Interceptors.Caching.Abstractions --version 1.0.0.96
#r "nuget: Innovabit.DotNet.Interceptors.Caching.Abstractions, 1.0.0.96"
#:package Innovabit.DotNet.Interceptors.Caching.Abstractions@1.0.0.96
#addin nuget:?package=Innovabit.DotNet.Interceptors.Caching.Abstractions&version=1.0.0.96
#tool nuget:?package=Innovabit.DotNet.Interceptors.Caching.Abstractions&version=1.0.0.96
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'sIMemoryCache.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:
CancellationTokenparameters — 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, anIProgress<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 (ignoringCancellationTokenand[CacheKeyIgnore]parameters). Replace withUseCacheKeyGenerator<T>().ICacheSerializer— how values are serialized for distributed stores. Default:System.Text.Json. Replace withUseCacheSerializer<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 | Versions 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. |
-
net10.0
- Innovabit.DotNet.Interceptors.Abstractions (>= 1.0.0.96)
-
net8.0
- Innovabit.DotNet.Interceptors.Abstractions (>= 1.0.0.96)
- System.Text.Json (>= 10.0.12)
-
net9.0
- Innovabit.DotNet.Interceptors.Abstractions (>= 1.0.0.96)
- System.Text.Json (>= 10.0.12)
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.