Soenneker.SemanticKernel.Cache.Options 4.0.277

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

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.SemanticKernel.Cache.Options

A concurrent, keyed cache for lazily created SemanticKernelOptions instances.

Installation

dotnet add package Soenneker.SemanticKernel.Cache.Options

Registration

using Soenneker.SemanticKernel.Cache.Options.Registrars;

services.AddSemanticKernelOptionsCacheAsSingleton();

Singleton registration shares option objects across consumers. AddSemanticKernelOptionsCacheAsScoped() creates an independent cache for each DI scope.

Usage

using Soenneker.SemanticKernel.Cache.Options.Abstract;
using Soenneker.SemanticKernel.Dtos.Options;

SemanticKernelOptions options = await optionsCache.Get(
    "primary-chat",
    () => ValueTask.FromResult(new SemanticKernelOptions
    {
        ModelId = configuration["Models:Primary:ModelId"],
        Endpoint = configuration["Models:Primary:Endpoint"],
        ApiKey = configuration["Models:Primary:ApiKey"],
        RequestsPerMinute = 60,
        MaxTokens = 2_000
    }),
    cancellationToken);

Concurrent callers for the same key share one initialization. The first successfully created object remains associated with that key; factories passed by later calls are not invoked until the entry is removed.

bool removed = await optionsCache.Remove("primary-chat");
SemanticKernelOptions replacement = await optionsCache.Get(
    "primary-chat",
    () => LoadReplacementOptions());

Important behavior

  • Cached options are mutable and returned by reference. Treat them as read-only after publication, or coordinate mutations because every consumer of that key sees the same object.
  • The Get cancellation token controls waiting for cache initialization, but the factory delegate itself does not receive that token. Capture a suitable token explicitly if the factory performs cancellable work.
  • GetAll returns a dictionary snapshot; the contained option objects are the same cached references.
  • Clear and disposal remove entries. They cannot erase immutable strings such as an API key already stored in an options object.

Use different keys for different model, endpoint, credential, rate-limit, or generation configurations. Removing a cached options entry does not remove a Kernel already created from it in a separate kernel cache.

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

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.282 0 10/13/2026
4.0.281 23 10/13/2026
4.0.280 33 10/13/2026
4.0.277 52 10/12/2026
4.0.276 52 10/11/2026
4.0.275 53 10/11/2026
4.0.274 47 10/11/2026
4.0.273 87 10/6/2026
4.0.272 87 9/30/2026
4.0.271 90 9/30/2026
4.0.270 90 9/29/2026
4.0.269 91 9/29/2026
4.0.268 98 9/25/2026
4.0.267 101 9/25/2026
4.0.266 102 9/25/2026
4.0.265 97 9/24/2026
4.0.264 90 9/24/2026
4.0.263 103 9/17/2026
4.0.262 99 9/16/2026
4.0.261 100 9/16/2026
Loading failed

Update dependency Soenneker.Dictionaries.Singletons to 4.0.115 (#821)