Soenneker.SemanticKernel.Cache 4.0.822

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

A concurrent, keyed cache that creates and reuses Microsoft Semantic Kernel Kernel instances.

Installation

dotnet add package Soenneker.SemanticKernel.Cache

Registration

using Soenneker.SemanticKernel.Cache.Registrars;

services.AddSemanticKernelCacheAsSingleton();

Singleton registration shares kernels across the application. AddSemanticKernelCacheAsScoped() instead creates an independent cache per DI scope and clears it when that scope is disposed.

Creating a kernel

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

var options = new SemanticKernelOptions
{
    ModelId = "chat-model",
    Endpoint = "https://model.example.com",
    ApiKey = configuration["Models:ApiKey"],
    KernelFactory = static (options, cancellationToken) =>
    {
        IKernelBuilder builder = Kernel.CreateBuilder();

        // Add the connector required by your application to builder here.

        return ValueTask.FromResult(builder);
    },
    ConfigureBuilder = builder =>
    {
        // Register plugins or services before Build(), if needed.
    },
    ConfigureKernel = async (kernel, cancellationToken) =>
    {
        // Perform asynchronous post-build configuration, if needed.
        await ValueTask.CompletedTask;
    }
};

Kernel kernel = await cache.Get("primary-chat", options, cancellationToken);

KernelFactory produces the builder. ConfigureBuilder runs before Build(), and ConfigureKernel runs after the kernel is built. If no factory is supplied, the cache builds an empty Kernel.CreateBuilder(); connector-specific options such as ModelId, Endpoint, and ApiKey are not applied automatically.

Key behavior

The ID is the cache identity. Concurrent requests for the same ID share one initialization, and subsequent calls return that kernel. The options passed during the first successful creation win; later options for the same ID do not reconfigure the existing kernel. Use distinct IDs for distinct configurations.

Kernel sameKernel = await cache.Get("primary-chat", options, cancellationToken);

bool removed = await cache.Remove("primary-chat", cancellationToken);
Kernel rebuilt = await cache.Get("primary-chat", replacementOptions, cancellationToken);

Init and Get both initialize on first access and return the cached instance. GetSync blocks while performing the same operation; prefer the asynchronous API when a factory or post-build configuration can perform asynchronous work.

Remove, Clear, and cache disposal remove and dispose cached kernels through the underlying singleton dictionary. Do not continue using a kernel after its key has been removed or its cache has been disposed. GetAll returns the initialized kernels as a dictionary snapshot for inspection; it does not initialize missing keys.

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 (1)

Showing the top 1 NuGet packages that depend on Soenneker.SemanticKernel.Cache:

Package Downloads
Soenneker.SemanticKernel.Pool

Manages a pool of Semantic Kernel instances with per-entry rate limiting.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.833 141 9/5/2026
4.0.832 96 9/4/2026
4.0.831 145 9/4/2026
4.0.830 48 9/4/2026
4.0.829 107 9/4/2026
4.0.828 104 9/3/2026
4.0.827 284 8/31/2026
4.0.826 204 8/31/2026
4.0.825 126 8/31/2026
4.0.824 129 8/31/2026
4.0.823 137 8/30/2026
4.0.822 82 8/30/2026
4.0.821 282 8/30/2026
4.0.820 202 8/30/2026
4.0.819 152 8/30/2026
4.0.818 192 8/30/2026
4.0.817 86 8/29/2026
4.0.816 132 8/29/2026
4.0.815 400 8/26/2026
4.0.814 156 8/26/2026
Loading failed

Improve Semantic Kernel cache documentation