Bsft.Caching
2.2.0
dotnet add package Bsft.Caching --version 2.2.0
NuGet\Install-Package Bsft.Caching -Version 2.2.0
<PackageReference Include="Bsft.Caching" Version="2.2.0" />
<PackageVersion Include="Bsft.Caching" Version="2.2.0" />
<PackageReference Include="Bsft.Caching" />
paket add Bsft.Caching --version 2.2.0
#r "nuget: Bsft.Caching, 2.2.0"
#:package Bsft.Caching@2.2.0
#addin nuget:?package=Bsft.Caching&version=2.2.0
#tool nuget:?package=Bsft.Caching&version=2.2.0
Bsft.Caching
A memory or distributed cache store with the key builder, the tag index and the invalidator that
make an entry findable again when the data behind it changes. The mediator pipeline behavior that
serves cacheable queries from it ships in Bsft.Caching.Mediator.
Install
dotnet add package Bsft.Caching
Requires Microsoft.Extensions.Caching.Memory and the usual Microsoft.Extensions.* abstractions. No further
Bsft packages. With CacheProvider.Distributed the application registers its own IDistributedCache;
this package does not pick one for you.
Register
services.AddBsftCaching(options =>
{
options.DefaultTimeToLive = TimeSpan.FromMinutes(10);
options.KeyPrefix = "okej";
});
// or bound from configuration, section "Bsft:Caching"
services.AddBsftCaching(configuration);
Nothing else is required for the memory provider, which is the default. CacheProvider.Distributed
takes one more line, because the store reads through an IDistributedCache this package does not
choose:
services.AddStackExchangeRedisCache(redis => redis.Configuration = "…");
services.AddBsftCaching(options => options.Provider = CacheProvider.Distributed);
To cache mediator queries, add Bsft.Caching.Mediator and call
AddBsftCachingMediator() after AddBsftMediator and after every authorization behavior: the
mediator runs behaviors in registration order, innermost last, so a behavior registered after
the cache no longer runs on a hit. A query opts in by implementing ICacheable; a command carrying
the marker is still dispatched to its handler.
Configure
| Option | Default | Effect |
|---|---|---|
BsftCachingOptions.Provider |
CacheProvider.Memory |
Which cache is written to. Distributed requires the host to register an IDistributedCache. Read once at registration, because it decides which store type is registered. |
BsftCachingOptions.DefaultTimeToLive |
00:05:00 |
The lifetime applied to an entry whose request does not state one of its own through ICacheable.TimeToLive. |
BsftCachingOptions.KeyPrefix |
bsft |
The prefix every key starts with, which is what keeps this framework's entries apart from other writers on a shared distributed cache. |
Validation: ValidateOnStart() rejects a non-positive DefaultTimeToLive, an empty KeyPrefix and a
Provider that is not a defined value — all of them reported in one message. Before 1.3.5 the first of
these was an ArgumentOutOfRangeException thrown by AddBsftCaching, which never saw a value that
arrived through configuration.
Extend
Every seam is registered with TryAdd, so registering your own before AddBsftCaching wins.
ICacheStore — reads and writes entries. MemoryCacheStore and DistributedCacheStore ship;
which one is registered follows Provider.
ICacheTagIndex — records which keys carry which tag. The shipped CacheTagIndex is in-process and
volatile for either provider, so on a distributed cache InvalidateTagAsync evicts only what this
instance cached since it started. An application that needs tag invalidation to reach the whole fleet
replaces it with one over shared storage; that is the single most likely replacement here.
ICacheKeyBuilder — composes the key from prefix, scope, request type and discriminator, or returns
null when the scope is CacheKeyScope.NotCacheable.
ICacheKeyScopeProvider — supplies the ambient scope every key is qualified with, as a
CacheKeyScope: Global, For(discriminator), or NotCacheable when the ambient context did not
resolve and the request must therefore bypass the cache entirely — no read and no write. The shipped
GlobalCacheKeyScopeProvider returns Global; a multi-tenant host replaces it so that one tenant
cannot be served another's result, most simply by referencing Bsft.Caching.Data and calling
AddBsftCachingData().
ICacheSerializer — turns a value into bytes for the distributed store; JsonCacheSerializer ships.
ICacheInvalidator — evicts by key or by tag, and forgets the association afterwards.
Documentation
Topic page: docs/caching.md. Conventions: docs/package-conventions.md.
| 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 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 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
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Caching.Memory (>= 10.0.12)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.12)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Logging (>= 10.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Options (>= 10.0.12)
-
net8.0
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.19)
- Microsoft.Extensions.Caching.Memory (>= 9.0.19)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.19)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.19)
- Microsoft.Extensions.Logging (>= 9.0.19)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.19)
- Microsoft.Extensions.Options (>= 9.0.19)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Bsft.Caching:
| Package | Downloads |
|---|---|
|
Bsft.Caching.Mediator
BSFT Framework mediator pipeline behavior that serves cacheable queries from the Bsft.Caching store and writes the handler's result back on a miss. |
|
|
Bsft.Caching.Data
BSFT Framework bridge that folds the current tenant into every Bsft.Caching key, so a cacheable query answered for one tenant is never served to another. |
|
|
Bsft.Caching.EventAggregator
BSFT Framework cache invalidation driven by the in-process Bsft.EventAggregator: key and tag invalidation events evict cached query results |
GitHub repositories
This package is not used by any popular GitHub repositories.