Soenneker.Utils.HttpClientCache 4.0.1846

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

Providing thread-safe singleton HttpClients

Why?

'Long-lived' HttpClient static/singleton instances is the recommended use pattern in .NET. Avoid the unnecessary overhead of IHttpClientFactory, and definitely avoid creating a new HttpClient instance per request.

HttpClientCache provides a thread-safe singleton HttpClient instance per key via dependency injection. HttpClients are created lazily, and disposed on application shutdown (or manually if you want).

See Guidelines for using HttpClient

Installation

dotnet add package Soenneker.Utils.HttpClientCache

Usage

  1. Register IHttpClientCache within DI (Program.cs).
public static async Task Main(string[] args)
{
    ...
    builder.Services.AddHttpClientCache();
}
  1. Inject IHttpClientCache via constructor, and retrieve a fresh HttpClient.

Example:

public class TestClass
{
    IHttpClientCache _httpClientCache;

    public TestClass(IHttpClientCache httpClientCache)
    {
        _httpClientCache = httpClientCache;
    }

    public async ValueTask<string> GetGoogleSource()
    {
        HttpClient httpClient = await _httpClientCache.Get(nameof(TestClass));

        var response = await httpClient.GetAsync("https://www.google.com");
        response.EnsureSuccessStatusCode();

        var responseString = await response.Content.ReadAsStringAsync();
        return responseString;
    }
}
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 (42)

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.Blob.Service

A utility library for Azure Blob storage service client operations

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.1848 213 2/12/2026
4.0.1847 1,155 2/12/2026
4.0.1846 2,652 2/11/2026
4.0.1845 3,226 2/10/2026
4.0.1844 980 2/10/2026
4.0.1843 4,563 2/10/2026
4.0.1842 6,994 2/6/2026
4.0.1841 1,509 2/6/2026
4.0.1840 5,081 2/4/2026
4.0.1839 9,745 1/28/2026
4.0.1838 7,629 1/23/2026
4.0.1837 2,795 1/22/2026
4.0.1836 3,391 1/22/2026
4.0.1835 90 1/22/2026
4.0.1834 2,170 1/22/2026
4.0.1833 3,415 1/21/2026
4.0.1832 3,537 1/21/2026
4.0.1831 2,823 1/20/2026
4.0.1830 7,782 1/18/2026
4.0.1829 2,081 1/18/2026
Loading failed