{"id":24271689,"url":"https://github.com/soenneker/soenneker.utils.httpclientcache","last_synced_at":"2026-05-02T23:05:57.208Z","repository":{"id":197508923,"uuid":"698787574","full_name":"soenneker/soenneker.utils.httpclientcache","owner":"soenneker","description":"A utility library for singleton thread-safe HttpClients","archived":false,"fork":false,"pushed_at":"2026-04-14T20:12:55.000Z","size":2245,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-14T20:22:58.416Z","etag":null,"topics":["csharp","dotnet","httpclient","utils"],"latest_commit_sha":null,"homepage":"https://soenneker.com","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soenneker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"soenneker","thanks_dev":"soenneker"}},"created_at":"2023-10-01T01:04:37.000Z","updated_at":"2026-04-14T20:13:00.000Z","dependencies_parsed_at":"2026-03-12T06:04:15.259Z","dependency_job_id":null,"html_url":"https://github.com/soenneker/soenneker.utils.httpclientcache","commit_stats":null,"previous_names":["soenneker/soenneker.utils.httpclientcache"],"tags_count":232,"template":false,"template_full_name":null,"purl":"pkg:github/soenneker/soenneker.utils.httpclientcache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenneker%2Fsoenneker.utils.httpclientcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenneker%2Fsoenneker.utils.httpclientcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenneker%2Fsoenneker.utils.httpclientcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenneker%2Fsoenneker.utils.httpclientcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soenneker","download_url":"https://codeload.github.com/soenneker/soenneker.utils.httpclientcache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenneker%2Fsoenneker.utils.httpclientcache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31826902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T18:05:02.291Z","status":"online","status_checked_at":"2026-04-15T02:00:06.175Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","httpclient","utils"],"created_at":"2025-01-15T17:59:18.412Z","updated_at":"2026-04-15T05:01:12.502Z","avatar_url":"https://github.com/soenneker.png","language":"C#","funding_links":["https://github.com/sponsors/soenneker","https://thanks.dev/soenneker"],"categories":[],"sub_categories":[],"readme":"[![](https://img.shields.io/nuget/v/Soenneker.Utils.HttpClientCache.svg?style=for-the-badge)](https://www.nuget.org/packages/Soenneker.Utils.HttpClientCache/)\n[![](https://img.shields.io/github/actions/workflow/status/soenneker/soenneker.utils.httpclientcache/publish-package.yml?style=for-the-badge)](https://github.com/soenneker/soenneker.utils.httpclientcache/actions/workflows/publish-package.yml)\n[![](https://img.shields.io/nuget/dt/Soenneker.Utils.HttpClientCache.svg?style=for-the-badge)](https://www.nuget.org/packages/Soenneker.Utils.HttpClientCache/)\n[![](https://img.shields.io/github/actions/workflow/status/soenneker/soenneker.utils.httpclientcache/codeql.yml?label=CodeQL\u0026style=for-the-badge)](https://github.com/soenneker/soenneker.utils.httpclientcache/actions/workflows/codeql.yml)\n\n# ![](https://user-images.githubusercontent.com/4441470/224455560-91ed3ee7-f510-4041-a8d2-3fc093025112.png) Soenneker.Utils.HttpClientCache\n### Providing thread-safe singleton HttpClients\n\n### Why?\n\n'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.\n\n`HttpClientCache` provides a thread-safe singleton `HttpClient` instance per key via dependency injection. `HttpClient`s are created lazily, and disposed on application shutdown (or manually if you want).\n\nSee [Guidelines for using HttpClient](https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines)\n\n## Installation\n\n```\ndotnet add package Soenneker.Utils.HttpClientCache\n```\n\n## Usage\n\n1. Register `IHttpClientCache` within DI (`Program.cs`).\n\n```csharp\npublic static async Task Main(string[] args)\n{\n    ...\n    builder.Services.AddHttpClientCache();\n}\n```\n\n2. Inject `IHttpClientCache` via constructor, and retrieve a fresh `HttpClient`.\n\nExample:\n\n```csharp\npublic class TestClass\n{\n    IHttpClientCache _httpClientCache;\n\n    public TestClass(IHttpClientCache httpClientCache)\n    {\n        _httpClientCache = httpClientCache;\n    }\n\n    public async ValueTask\u003cstring\u003e GetGoogleSource()\n    {\n        HttpClient httpClient = await _httpClientCache.Get(nameof(TestClass));\n\n        var response = await httpClient.GetAsync(\"https://www.google.com\");\n        response.EnsureSuccessStatusCode();\n\n        var responseString = await response.Content.ReadAsStringAsync();\n        return responseString;\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoenneker%2Fsoenneker.utils.httpclientcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoenneker%2Fsoenneker.utils.httpclientcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoenneker%2Fsoenneker.utils.httpclientcache/lists"}