Reliable.HttpClient.Caching 1.3.0

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

Reliable.HttpClient.Caching

NuGet Version

Intelligent HTTP response caching extension for Reliable.HttpClient with preset-based configuration, custom headers support, and automatic memory management.

Installation

dotnet add package Reliable.HttpClient.Caching

Quick Start

// Zero configuration - just add resilience with caching
services.AddHttpClient<WeatherApiClient>()
    .AddResilienceWithMediumTermCache<WeatherResponse>(); // 10 minutes cache

// Configure default headers for all requests
services.AddHttpClient<ApiClient>()
    .AddMemoryCache(options => options
        .WithDefaultExpiry(TimeSpan.FromMinutes(5))
        .AddHeader("Authorization", "Bearer token")
        .AddHeader("X-API-Version", "1.0"));

// Use anywhere with per-request header customization
public class WeatherService(CachedHttpClient<WeatherResponse> client)
{
    public async Task<WeatherResponse> GetWeatherAsync(string city) =>
        await client.GetFromJsonAsync($"/weather?city={city}");

    // Add custom headers per request
    public async Task<WeatherResponse> GetWeatherWithTokenAsync(string city, string token)
    {
        var headers = new Dictionary<string, string>
        {
            ["Authorization"] = $"Bearer {token}",
            ["X-Request-ID"] = Guid.NewGuid().ToString()
        };
        return await client.GetFromJsonAsync($"/weather?city={city}", headers);
    }
}

Why This Package?

  • Zero Configuration – Works out of the box with sensible defaults
  • ✨ Custom Headers Support – Default headers + per-request header customization with smart cache key generation
  • Preset-Based Setup – 6 ready-made configurations for common scenarios
  • Automatic Dependencies – No need to manually register IMemoryCache
  • Combined APIs – Resilience + Caching in one method call
  • Performance Optimized – Smart cache keys, configurable expiry, memory-efficient

Caching Approaches

This package provides two caching approaches:

🌐 Universal Caching

  • Best for: Multiple response types in a single client
  • Key class: HttpClientWithCache
  • Use case: Flexible, multi-type scenarios

🎯 Generic Caching

  • Best for: Type-safe caching for specific response types
  • Key class: CachedHttpClient<TResponse>
  • Use case: High-performance, type-safe scenarios
  • 📚 See Generic Documentation →

🎯 Need help choosing? See our Choosing Guide

Ready-Made Presets

Choose from preset configurations for common scenarios:

// Short-term (1 minute) - frequently changing data
services.AddHttpClient<ApiClient>()
    .AddShortTermCache<ApiResponse>();

// Medium-term (10 minutes) - moderately stable data
services.AddHttpClient<ApiClient>()
    .AddMediumTermCache<ApiResponse>();

// Long-term (1 hour) - stable reference data
services.AddHttpClient<ApiClient>()
    .AddLongTermCache<ApiResponse>();

Documentation

📖 Complete Documentation - Full caching guide with examples 🎯 Choosing Guide - Which approach to use when 📝 Examples - Real-world usage scenarios

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  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 (2)

Showing the top 2 NuGet packages that depend on Reliable.HttpClient.Caching:

Package Downloads
KodySu.Client

Типобезопасный клиент для API kody.su (поиск информации по телефонным номерам).

Planfact.KodySu.Client

Идиоматичный и типобезопасный клиент для API kody.su v2.1 (поиск информации по телефонным номерам) с поддержкой отказоустойчивых соединений и кеширования.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.4.0 181 9/24/2025
1.3.0 193 9/22/2025
1.2.0 273 9/18/2025
1.1.0 278 9/18/2025
1.0.2 927 8/29/2025
1.0.1 164 8/29/2025
1.0.0 169 8/29/2025
1.0.0-alpha1 184 8/29/2025

🎉 v1.3.0 Release - PATCH Method Support & Enhanced Caching!

     ✨ Major New Features:
     • Complete HTTP PATCH method support in HttpClientWithCache and CachedHttpClient<T>
     • Four PATCH method overloads matching main HttpClient module capabilities
     • Intelligent cache invalidation for PATCH operations - responses not cached, but related
     cache entries invalidated
     • Full header support for PATCH operations including OAuth and authentication scenarios
     • Smart error handling - cache remains intact if PATCH operation fails

     🔧 API Enhancements:
     • PatchAsync<TRequest, TResponse>(uri, request) - Typed request/response with cache
     invalidation
     • PatchAsync<TRequest, TResponse>(uri, request, headers) - With custom headers support
     • PatchAsync<TRequest>(uri, request) - Returns raw HttpResponseMessage
     • PatchAsync<TRequest>(uri, request, headers) - Raw response with headers
     • Consistent caching behavior: GET operations cached, mutating operations (POST, PUT, PATCH)
     invalidate cache
     • Comprehensive test coverage (336+ tests) validating all PATCH scenarios

     🎯 Key Use Cases:
     • RESTful API updates with intelligent cache management
     • Partial resource updates with cache invalidation patterns
     • Authentication-aware PATCH operations with header support
     • Multi-tenant PATCH operations with isolated cache invalidation
     • Error-resilient updates that preserve cache integrity on failures

     🚀 Quick Start:
     // PATCH with automatic cache invalidation
     var updated = await client.PatchAsync<UpdateRequest, UserResponse>("/users/123",
     request);

     // PATCH with headers and cache management
     await client.PatchAsync("/api/resource", data, headers);

     🔄 Previous Features (v1.2.0):
     • Full custom headers support matching main HttpClient module capabilities
     • DefaultHeaders property in HttpCacheOptions for static headers across all cached requests
     • Per-request headers support in all HTTP methods (GET, POST, PUT, DELETE)
     • Intelligent cache key generation that includes headers for proper cache isolation
     • Enhanced HttpClientWithCache with comprehensive header support

     📚 Full documentation: https://github.com/akrisanov/Reliable.HttpClient

     ⚡ Breaking Changes: None - fully backward compatible