Soenneker.Utils.HttpClientCache
4.0.2051
Prefix Reserved
dotnet add package Soenneker.Utils.HttpClientCache --version 4.0.2051
NuGet\Install-Package Soenneker.Utils.HttpClientCache -Version 4.0.2051
<PackageReference Include="Soenneker.Utils.HttpClientCache" Version="4.0.2051" />
<PackageVersion Include="Soenneker.Utils.HttpClientCache" Version="4.0.2051" />
<PackageReference Include="Soenneker.Utils.HttpClientCache" />
paket add Soenneker.Utils.HttpClientCache --version 4.0.2051
#r "nuget: Soenneker.Utils.HttpClientCache, 4.0.2051"
#:package Soenneker.Utils.HttpClientCache@4.0.2051
#addin nuget:?package=Soenneker.Utils.HttpClientCache&version=4.0.2051
#tool nuget:?package=Soenneker.Utils.HttpClientCache&version=4.0.2051
Soenneker.Utils.HttpClientCache
Provides lazily created, reusable HttpClient instances keyed by application-defined identifiers.
Installation
dotnet add package Soenneker.Utils.HttpClientCache
Registration
using Soenneker.Utils.HttpClientCache.Registrar;
services.AddHttpClientCacheAsSingleton();
Use AddHttpClientCacheAsScoped() only when every dependency-injection scope should own and dispose an independent cache.
Create or retrieve a client
using System.Net;
using Soenneker.Dtos.HttpClientOptions;
using Soenneker.Utils.HttpClientCache.Abstract;
HttpClient client = await cache.Get(
"catalog-api",
static () => new HttpClientOptions
{
BaseAddress = new Uri("https://catalog.example.com/"),
Timeout = TimeSpan.FromSeconds(30),
ConnectTimeout = TimeSpan.FromSeconds(5),
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
DefaultRequestHeaders = new Dictionary<string, string>
{
["Accept"] = "application/json"
}
},
cancellationToken);
The options factory runs only when that key is first initialized. Later calls with the same key return the same HttpClient and ignore new factories/options. Use a stable, unique key for each logical client configuration.
Do not dispose a returned client. Remove and dispose one cache entry with Remove/RemoveSync, or dispose the cache to release all owned clients and dedicated handlers.
Handler behavior
Handlers with the same transport options can be shared across cache keys. Cookies are disabled on shared handlers. Setting UseCookieContainer = true creates a dedicated, cache-owned handler and cookie container for that client so cookies are not shared between keys.
ModifyPrimaryHandler, Proxy, SslOptions, or delegating handlers also require dedicated transports. Delegating handler factories run once during client creation; each must return a new handler with InnerHandler unset. The first factory in the list becomes the outermost handler.
ModifyClient runs once after base address, timeout, and default headers are applied. It can perform asynchronous initialization.
Security and lifecycle notes
- Default request headers are added without semantic validation. Use only trusted header names and values.
- Automatic redirects can forward non-
Authorizationcustom headers to another host. Disable redirects for clients carrying secrets in custom headers unless every redirect target is trusted. - Custom certificate validation in
SslOptionsorModifyPrimaryHandlerchanges the TLS trust boundary; avoid permissive callbacks. - The cache does not retry, enforce successful status codes, or dispose response messages. Callers own each response and response stream.
- Browser targets do not support custom primary/delegating handler configuration.
Synchronous GetSync overloads are available for callers that cannot use asynchronous initialization. Prefer asynchronous Get when an options factory performs I/O.
| Product | Versions 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. |
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.11)
- Soenneker.Dictionaries.Singletons (>= 4.0.90)
- Soenneker.Dtos.HttpClientOptions (>= 4.0.31)
- Soenneker.Utils.Runtime (>= 4.0.1086)
NuGet packages (145)
Showing the top 5 NuGet packages that depend on Soenneker.Utils.HttpClientCache:
| Package | Downloads |
|---|---|
|
Soenneker.Cosmos.Client
A utility library for Azure Cosmos client accessibility |
|
|
Soenneker.Blob.Container
A utility library for Azure Blob storage container operations |
|
|
Soenneker.Validators.Email.Disposable.Online
A validation module checking for disposable email addresses via online sources |
|
|
Soenneker.Queue.Client
A utility library for Azure Queue (Storage) client accessibility |
|
|
Soenneker.GitHub.Client.Http
Provides a configured, cached HttpClient for GitHub's REST API. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.2051 | 4,340 | 9/1/2026 |
| 4.0.2050 | 5,453 | 8/31/2026 |
| 4.0.2049 | 2,816 | 8/31/2026 |
| 4.0.2048 | 5,252 | 8/31/2026 |
| 4.0.2047 | 385 | 8/31/2026 |
| 4.0.2046 | 429 | 8/31/2026 |
| 4.0.2045 | 1,031 | 8/31/2026 |
| 4.0.2044 | 3,135 | 8/30/2026 |
| 4.0.2043 | 3,238 | 8/30/2026 |
| 4.0.2041 | 1,036 | 8/30/2026 |
| 4.0.2040 | 1,851 | 8/30/2026 |
| 4.0.2039 | 74 | 8/30/2026 |
| 4.0.2038 | 2,190 | 8/30/2026 |
| 4.0.2037 | 284 | 8/30/2026 |
| 4.0.2035 | 1,128 | 8/29/2026 |
| 4.0.2033 | 3,951 | 8/29/2026 |
| 4.0.2032 | 537 | 8/29/2026 |
| 4.0.2031 | 37,028 | 8/26/2026 |
| 4.0.2030 | 4,847 | 8/26/2026 |
| 4.0.2029 | 1,836 | 8/26/2026 |
Updated NuGet packages