Soenneker.SemanticKernel.Cache 3.0.489

Prefix Reserved
dotnet add package Soenneker.SemanticKernel.Cache --version 3.0.489
                    
NuGet\Install-Package Soenneker.SemanticKernel.Cache -Version 3.0.489
                    
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="3.0.489" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.SemanticKernel.Cache" Version="3.0.489" />
                    
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 3.0.489
                    
#r "nuget: Soenneker.SemanticKernel.Cache, 3.0.489"
                    
#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.
#addin nuget:?package=Soenneker.SemanticKernel.Cache&version=3.0.489
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.SemanticKernel.Cache&version=3.0.489
                    
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

Providing async thread-safe singleton Semantic Kernel instances

Why?

When using Microsoft.SemanticKernel, it's important to centralize and reuse kernel setup logic rather than repeating configuration for each consumer or request. This avoids the overhead of reinitializing connectors and plugins. SemanticKernelCache supports this by providing a thread-safe, per-key singleton cache that lazily creates Kernel instances using customizable options. Kernels are disposed at application shutdown or manually if needed.

Installation

Install the package via the .NET CLI:

dotnet add package Soenneker.SemanticKernel.Cache

Usage

1. Register the Cache in Dependency Injection

In your Program.cs (or equivalent startup file), register the cache with the DI container:

using Soenneker.SemanticKernel.Cache;

public static async Task Main(string[] args)
{
    var builder = WebApplication.CreateBuilder(args);

    // Register SemanticKernelCache as a singleton service.
    builder.Services.AddSemanticKernelCacheAsSingleton();

    // Other configuration...
}

2. Inject and Retrieve a Kernel Instance

Inject ISemanticKernelCache into your classes and retrieve a Microsoft.SemanticKernel.Kernel instance by providing the required options.

using System.Threading;
using System.Threading.Tasks;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Chat;
using Soenneker.SemanticKernel.Cache;

public class TestClass
{
    private readonly ISemanticKernelCache _semanticKernelCache;
    private readonly SemanticKernelOptions _options;

    public TestClass(ISemanticKernelCache semanticKernelCache)
    {
        _semanticKernelCache = semanticKernelCache;
        
        // Create the options object once. Replace these with your actual values.
        var options = new SemanticKernelOptions
        {
            ModelId = "deepseek-r1:32b",
            Endpoint = "http://localhost:11434",
            KernelFactory = (opts, ct) =>
            {
                IKernelBuilder builder = Kernel.CreateBuilder().AddOllamaChatCompletion(opts.ModelId, new Uri(opts.Endpoint));

                return ValueTask.FromResult(builder);
            }
        };
    }

    public async async ValueTask<string> GetKernelResponse(string input, CancellationToken cancellationToken = default)
    {
        // Retrieve (or create) the kernel instance using a key (here, nameof(TestClass)).
        Kernel kernel = await _semanticKernelCache.Get(nameof(TestClass), _options, cancellationToken);

        // Retrieve the chat completion service from the kernel.
        var chatCompletionService = kernel.GetRequiredService<IChatCompletionService>();

        // Create a chat history and add the user's message.
        var history = new ChatHistory();
        history.AddUserMessage(input);

        // Request a chat completion using the chat service.
        var chatResult = await chatCompletionService.GetChatMessageContentAsync(history, kernel: kernel);

        // Return the chat result (or process it further as needed).
        return chatResult.ToString();
    }
}

Extending for Different Connectors/Plugins

The SemanticKernelOptions class includes an optional KernelFactory delegate. This allows you to override the default behavior (which uses the Azure Text Completion service) and create the kernel using a different connector or plugin. For example:

var openAiOptions = new SemanticKernelOptions
{
    ModelId = "openai-model-id",
    Endpoint = "https://api.openai.com/v1/",
    ApiKey = "your-openai-api-key",
    KernelFactory = (opts, ct) =>
    {
        Kernel kernel = new KernelBuilder().AddOpenAITextCompletionService(opts.ModelId, opts.Endpoint, opts.ApiKey);

        return ValueTask.FromResult(kernel);
    },
    ConfigureKernelAsync = async kernel =>
    {
        // Optionally, import skills or perform additional configuration.
        await ValueTask.CompletedTask;
    }
};

Kernel openAiKernel = await semanticKernelCache.Get("openaiKernel", openAiOptions);

This design makes it straightforward to support multiple types of Semantic Kernel configurations using the same caching mechanism.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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
3.0.489 238 7/9/2025
3.0.488 135 7/9/2025
3.0.487 119 7/9/2025
3.0.486 101 7/9/2025
3.0.485 142 7/8/2025
3.0.484 146 7/8/2025
3.0.483 337 7/4/2025
3.0.482 275 7/1/2025
3.0.481 124 7/1/2025
3.0.480 264 6/28/2025
3.0.479 74 6/28/2025
3.0.478 52 6/28/2025
3.0.477 137 6/28/2025
3.0.476 52 6/28/2025
3.0.475 150 6/28/2025
3.0.474 53 6/28/2025
3.0.473 51 6/28/2025
3.0.472 64 6/27/2025
3.0.471 62 6/27/2025
3.0.470 73 6/27/2025
3.0.469 280 6/26/2025
3.0.468 170 6/25/2025
3.0.467 196 6/25/2025
3.0.466 180 6/24/2025
3.0.465 326 6/16/2025
3.0.464 131 6/16/2025
3.0.463 359 6/11/2025
3.0.462 320 6/11/2025
3.0.461 341 6/11/2025
3.0.460 356 6/11/2025
3.0.459 273 6/11/2025
3.0.458 276 6/11/2025
3.0.457 271 6/11/2025
3.0.456 309 6/10/2025
3.0.455 398 6/3/2025
3.0.454 165 6/3/2025
3.0.453 310 6/3/2025
3.0.452 192 6/2/2025
3.0.451 184 6/2/2025
3.0.450 249 5/28/2025
3.0.449 188 5/28/2025
3.0.448 192 5/28/2025
3.0.447 138 5/28/2025
3.0.446 155 5/27/2025
3.0.445 136 5/27/2025
3.0.444 194 5/27/2025
3.0.443 140 5/27/2025
3.0.442 181 5/27/2025
3.0.441 132 5/27/2025
3.0.440 150 5/27/2025
3.0.439 296 5/26/2025
3.0.438 129 5/25/2025
3.0.437 133 5/25/2025
3.0.436 128 5/23/2025
3.0.435 145 5/23/2025
3.0.434 145 5/23/2025
3.0.433 106 5/23/2025
3.0.432 136 5/23/2025
3.0.431 115 5/23/2025
3.0.430 141 5/23/2025
3.0.429 159 5/23/2025
3.0.428 130 5/23/2025
3.0.427 141 5/22/2025
3.0.426 131 5/22/2025
3.0.425 164 5/22/2025
3.0.424 350 5/21/2025
3.0.423 164 5/21/2025
3.0.422 201 5/20/2025
3.0.421 135 5/20/2025
3.0.420 193 5/19/2025
3.0.419 303 5/18/2025
3.0.418 156 5/18/2025
3.0.417 157 5/18/2025
3.0.416 169 5/18/2025
3.0.414 97 5/18/2025
3.0.413 158 5/16/2025
3.0.412 181 5/16/2025
3.0.411 221 5/14/2025
3.0.410 220 5/14/2025
3.0.409 220 5/14/2025
3.0.408 219 5/14/2025
3.0.407 224 5/14/2025
3.0.406 137 5/8/2025
3.0.405 136 5/8/2025
3.0.404 139 5/8/2025
3.0.403 136 5/8/2025
3.0.402 134 5/8/2025
3.0.401 144 5/8/2025
3.0.400 140 5/8/2025
3.0.399 143 5/7/2025
3.0.398 142 5/6/2025
3.0.397 137 5/6/2025
3.0.396 138 5/6/2025
3.0.395 138 5/5/2025
3.0.394 144 5/5/2025
3.0.393 136 5/5/2025
3.0.392 141 5/5/2025
3.0.391 147 5/5/2025
3.0.390 137 5/5/2025
3.0.389 134 5/5/2025
3.0.388 137 5/5/2025
3.0.387 137 5/5/2025
3.0.386 139 5/5/2025
3.0.385 136 4/29/2025
3.0.384 132 4/27/2025
3.0.383 86 4/27/2025
3.0.382 82 4/26/2025
3.0.381 83 4/26/2025
3.0.380 171 4/18/2025
3.0.379 130 4/11/2025
3.0.378 165 4/9/2025
3.0.377 154 4/9/2025
3.0.376 174 4/9/2025
3.0.375 168 4/9/2025
3.0.374 162 4/8/2025
3.0.373 160 4/8/2025
3.0.372 158 4/8/2025
3.0.371 170 4/8/2025
3.0.370 164 4/8/2025
3.0.369 156 4/8/2025
3.0.368 161 4/8/2025
3.0.367 160 4/8/2025
3.0.366 154 4/8/2025
3.0.365 155 4/8/2025
3.0.364 158 4/8/2025
3.0.363 164 4/8/2025
3.0.362 159 4/8/2025
3.0.361 165 4/8/2025
3.0.360 164 4/8/2025
3.0.359 161 4/7/2025
3.0.358 151 4/7/2025
3.0.357 161 4/7/2025
3.0.356 162 4/7/2025
3.0.355 153 4/7/2025
3.0.354 156 4/7/2025
3.0.353 155 4/7/2025
3.0.352 161 4/7/2025
3.0.351 153 4/7/2025
3.0.350 159 4/7/2025
3.0.349 149 4/7/2025
3.0.348 162 4/7/2025
3.0.347 157 4/7/2025
3.0.346 155 4/7/2025
3.0.345 162 4/7/2025
3.0.344 159 4/7/2025
3.0.343 156 4/7/2025
3.0.342 165 4/6/2025
3.0.341 155 4/6/2025
3.0.340 158 4/6/2025
3.0.339 157 4/6/2025
3.0.338 155 4/6/2025
3.0.337 158 4/6/2025
3.0.336 161 4/6/2025
3.0.335 157 4/6/2025
3.0.334 133 4/6/2025
3.0.333 130 4/6/2025
3.0.332 133 4/6/2025
3.0.331 129 4/6/2025
3.0.330 140 4/6/2025
3.0.329 137 4/6/2025
3.0.328 103 4/6/2025
3.0.327 114 4/6/2025
3.0.326 101 4/6/2025
3.0.325 106 4/5/2025
3.0.324 117 4/5/2025
3.0.323 82 4/5/2025
3.0.322 80 4/5/2025
3.0.321 84 4/5/2025
3.0.320 86 4/5/2025
3.0.319 87 4/5/2025
3.0.318 88 4/5/2025
3.0.317 88 4/5/2025
3.0.316 99 4/4/2025
3.0.315 95 4/4/2025
3.0.314 96 4/4/2025
3.0.313 145 4/4/2025
3.0.312 149 4/4/2025
3.0.311 143 4/4/2025
3.0.310 165 4/4/2025
3.0.309 151 4/4/2025
3.0.308 159 4/3/2025
3.0.307 158 4/3/2025
3.0.306 152 4/2/2025
3.0.305 159 4/1/2025
3.0.304 157 4/1/2025
3.0.303 151 4/1/2025
3.0.302 149 4/1/2025
3.0.301 152 4/1/2025
3.0.300 146 4/1/2025
3.0.299 160 4/1/2025
3.0.298 154 4/1/2025
3.0.297 152 4/1/2025
3.0.296 142 4/1/2025
3.0.295 145 3/31/2025
3.0.294 156 3/31/2025
3.0.293 142 3/31/2025
3.0.292 163 3/31/2025
3.0.291 152 3/30/2025
3.0.290 151 3/29/2025
3.0.289 90 3/29/2025
3.0.288 90 3/29/2025
3.0.287 96 3/29/2025
3.0.286 88 3/29/2025
3.0.285 99 3/29/2025
3.0.284 131 3/27/2025
3.0.283 145 3/27/2025
3.0.282 133 3/27/2025
3.0.281 131 3/27/2025
3.0.280 136 3/26/2025
3.0.279 469 3/26/2025
3.0.278 468 3/26/2025
3.0.277 470 3/26/2025
3.0.276 473 3/25/2025
3.0.275 473 3/25/2025
3.0.274 468 3/25/2025
3.0.273 478 3/25/2025
3.0.272 475 3/25/2025
3.0.271 476 3/25/2025
3.0.270 488 3/25/2025
3.0.269 89 3/21/2025
3.0.268 82 3/21/2025
3.0.267 92 3/21/2025
3.0.266 108 3/21/2025
3.0.265 107 3/21/2025
3.0.264 135 3/21/2025
3.0.263 133 3/21/2025
3.0.262 144 3/20/2025
3.0.261 141 3/20/2025
3.0.260 139 3/19/2025
3.0.259 141 3/19/2025
3.0.258 137 3/18/2025
3.0.257 137 3/18/2025
3.0.256 135 3/18/2025
3.0.255 143 3/18/2025
3.0.254 143 3/18/2025
3.0.253 138 3/18/2025
3.0.252 138 3/18/2025
3.0.251 144 3/18/2025
3.0.250 84 3/15/2025
3.0.249 67 3/15/2025
3.0.248 70 3/15/2025
3.0.247 72 3/15/2025
3.0.246 67 3/15/2025
3.0.245 62 3/15/2025
3.0.244 152 3/12/2025
3.0.243 158 3/12/2025
3.0.242 157 3/12/2025
3.0.241 153 3/12/2025
3.0.240 143 3/12/2025
3.0.239 147 3/12/2025
3.0.238 152 3/12/2025
3.0.237 152 3/12/2025
3.0.236 151 3/12/2025
3.0.235 150 3/12/2025
3.0.234 149 3/12/2025
3.0.233 160 3/11/2025
3.0.232 157 3/11/2025
3.0.231 154 3/11/2025
3.0.230 161 3/11/2025
3.0.229 154 3/11/2025
3.0.228 160 3/11/2025
3.0.227 153 3/11/2025
3.0.226 153 3/11/2025
3.0.225 162 3/11/2025
3.0.224 158 3/11/2025
3.0.223 160 3/11/2025
3.0.222 160 3/11/2025
3.0.221 210 3/7/2025
3.0.220 205 3/7/2025
3.0.219 202 3/7/2025
3.0.218 219 3/7/2025
3.0.217 207 3/7/2025
3.0.216 210 3/7/2025
3.0.215 205 3/7/2025
3.0.214 206 3/7/2025
3.0.213 212 3/7/2025
3.0.212 210 3/3/2025
3.0.211 107 3/2/2025
3.0.210 110 3/2/2025
3.0.209 94 3/2/2025
3.0.208 97 3/2/2025
3.0.207 93 3/2/2025
3.0.206 93 3/2/2025
3.0.205 91 3/2/2025
3.0.204 109 3/2/2025
3.0.203 81 3/2/2025
3.0.202 90 3/2/2025
3.0.201 100 3/2/2025
3.0.200 93 3/2/2025
3.0.199 91 3/2/2025
3.0.198 98 3/1/2025
3.0.197 94 3/1/2025
3.0.196 95 3/1/2025
3.0.195 91 3/1/2025
3.0.194 91 3/1/2025
3.0.193 95 3/1/2025
3.0.192 94 3/1/2025
3.0.191 94 3/1/2025
3.0.190 85 3/1/2025
3.0.189 89 3/1/2025
3.0.188 97 3/1/2025
3.0.187 89 3/1/2025
3.0.186 97 2/28/2025
3.0.185 97 2/26/2025
3.0.184 98 2/26/2025
3.0.183 95 2/26/2025
3.0.182 101 2/26/2025
3.0.181 94 2/26/2025
3.0.180 98 2/25/2025
3.0.179 94 2/25/2025
3.0.178 101 2/25/2025
3.0.177 96 2/25/2025
3.0.176 104 2/25/2025
3.0.175 100 2/25/2025
3.0.174 93 2/25/2025
3.0.173 98 2/25/2025
3.0.172 96 2/25/2025
3.0.171 97 2/24/2025
3.0.170 99 2/24/2025
3.0.169 89 2/24/2025
3.0.168 128 2/23/2025
3.0.167 88 2/23/2025
3.0.166 93 2/23/2025
3.0.165 91 2/23/2025
3.0.164 95 2/23/2025
3.0.163 90 2/23/2025
3.0.162 96 2/23/2025
3.0.161 89 2/23/2025
3.0.160 98 2/22/2025
3.0.159 92 2/22/2025
3.0.158 97 2/22/2025
3.0.157 94 2/22/2025
3.0.156 90 2/22/2025
3.0.155 94 2/22/2025
3.0.154 89 2/22/2025
3.0.153 94 2/22/2025
3.0.152 100 2/22/2025
3.0.151 94 2/22/2025
3.0.150 97 2/22/2025
3.0.149 99 2/22/2025
3.0.148 101 2/22/2025
3.0.147 95 2/22/2025
3.0.146 100 2/22/2025
3.0.145 91 2/22/2025
3.0.144 97 2/22/2025
3.0.143 86 2/22/2025
3.0.142 96 2/22/2025
3.0.141 96 2/21/2025
3.0.140 93 2/21/2025
3.0.139 93 2/21/2025
3.0.138 95 2/21/2025
3.0.137 88 2/21/2025
3.0.136 97 2/21/2025
3.0.135 97 2/21/2025
3.0.134 100 2/20/2025
3.0.133 101 2/19/2025
3.0.132 102 2/19/2025
3.0.131 102 2/19/2025
3.0.130 99 2/19/2025
3.0.129 109 2/19/2025
3.0.128 107 2/19/2025
3.0.127 111 2/19/2025
3.0.126 98 2/19/2025
3.0.125 101 2/19/2025
3.0.124 99 2/19/2025
3.0.123 103 2/19/2025
3.0.122 103 2/18/2025
3.0.121 99 2/18/2025
3.0.120 108 2/18/2025
3.0.119 99 2/18/2025
3.0.118 106 2/18/2025
3.0.117 106 2/18/2025
3.0.116 120 2/18/2025
3.0.115 99 2/18/2025
3.0.114 105 2/16/2025
3.0.113 105 2/14/2025
3.0.112 95 2/14/2025
3.0.111 95 2/14/2025
3.0.110 98 2/14/2025
3.0.109 106 2/14/2025
3.0.108 113 2/14/2025
3.0.107 108 2/14/2025
3.0.106 118 2/14/2025
3.0.105 101 2/13/2025
3.0.104 96 2/13/2025
3.0.103 113 2/13/2025
3.0.102 91 2/13/2025
3.0.101 114 2/12/2025
3.0.100 104 2/12/2025
3.0.99 104 2/12/2025
3.0.98 112 2/12/2025
3.0.97 106 2/12/2025
3.0.96 112 2/12/2025
3.0.95 102 2/12/2025
3.0.94 106 2/12/2025
3.0.93 104 2/12/2025
3.0.92 106 2/12/2025
3.0.91 102 2/12/2025
3.0.90 105 2/12/2025
3.0.89 100 2/12/2025
3.0.88 103 2/12/2025
3.0.87 109 2/12/2025
3.0.86 103 2/12/2025
3.0.85 111 2/12/2025
3.0.84 107 2/12/2025
3.0.83 99 2/12/2025
3.0.82 99 2/11/2025
3.0.81 100 2/11/2025
3.0.80 106 2/11/2025
3.0.79 102 2/11/2025
3.0.78 110 2/11/2025
3.0.77 109 2/11/2025
3.0.76 99 2/11/2025
3.0.75 108 2/11/2025
3.0.74 108 2/11/2025
3.0.73 124 2/11/2025
3.0.72 103 2/11/2025
3.0.71 106 2/11/2025
3.0.70 107 2/10/2025
3.0.69 110 2/10/2025
3.0.68 114 2/10/2025
3.0.67 108 2/10/2025
3.0.66 102 2/10/2025
3.0.65 103 2/10/2025
3.0.64 106 2/9/2025
3.0.63 109 2/9/2025
3.0.62 91 2/9/2025
3.0.61 102 2/9/2025
3.0.60 101 2/9/2025
3.0.59 92 2/9/2025
3.0.58 105 2/8/2025
3.0.57 107 2/8/2025
3.0.56 95 2/8/2025
3.0.55 110 2/8/2025
3.0.54 100 2/8/2025
3.0.53 108 2/8/2025
3.0.52 101 2/8/2025
3.0.51 98 2/8/2025
3.0.50 103 2/8/2025
3.0.49 115 2/8/2025
3.0.48 103 2/8/2025
3.0.47 96 2/8/2025
3.0.46 108 2/7/2025
3.0.45 104 2/7/2025
3.0.44 113 2/7/2025
3.0.43 105 2/7/2025
3.0.42 103 2/7/2025
3.0.41 103 2/7/2025
3.0.40 120 2/7/2025
3.0.39 114 2/7/2025
3.0.38 113 2/7/2025
3.0.37 109 2/7/2025
3.0.36 103 2/7/2025
3.0.35 102 2/7/2025
3.0.34 98 2/7/2025
3.0.33 115 2/7/2025
3.0.32 106 2/7/2025
3.0.31 108 2/7/2025
3.0.30 101 2/6/2025
3.0.29 106 2/6/2025
3.0.28 95 2/6/2025
3.0.27 88 2/6/2025
3.0.26 108 2/6/2025
3.0.25 100 2/5/2025
3.0.24 104 2/5/2025
3.0.23 103 2/5/2025
3.0.22 109 2/5/2025
3.0.21 104 2/5/2025
3.0.20 105 2/5/2025
3.0.19 113 2/5/2025
3.0.18 103 2/5/2025
3.0.17 100 2/5/2025
3.0.16 109 2/5/2025
3.0.15 99 2/5/2025
3.0.14 109 2/5/2025
3.0.13 97 2/5/2025
3.0.12 103 2/5/2025
3.0.11 107 2/5/2025
3.0.10 108 2/5/2025
3.0.9 103 2/5/2025
3.0.8 100 2/5/2025
3.0.7 110 2/3/2025
3.0.6 107 2/3/2025
3.0.5 106 2/3/2025
3.0.4 109 2/3/2025
3.0.3 106 2/3/2025