Bsft.Caching 2.2.0

dotnet add package Bsft.Caching --version 2.2.0
                    
NuGet\Install-Package Bsft.Caching -Version 2.2.0
                    
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="Bsft.Caching" Version="2.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bsft.Caching" Version="2.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Bsft.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 Bsft.Caching --version 2.2.0
                    
#r "nuget: Bsft.Caching, 2.2.0"
                    
#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 Bsft.Caching@2.2.0
                    
#: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=Bsft.Caching&version=2.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Bsft.Caching&version=2.2.0
                    
Install as a Cake Tool

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

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.

Version Downloads Last Updated
2.2.0 111 10/23/2026
2.1.0 154 9/28/2026