Http.Cache.Headers.MessageHandler
1.0.1-beta
See the version list below for details.
dotnet add package Http.Cache.Headers.MessageHandler --version 1.0.1-beta
NuGet\Install-Package Http.Cache.Headers.MessageHandler -Version 1.0.1-beta
<PackageReference Include="Http.Cache.Headers.MessageHandler" Version="1.0.1-beta" />
paket add Http.Cache.Headers.MessageHandler --version 1.0.1-beta
#r "nuget: Http.Cache.Headers.MessageHandler, 1.0.1-beta"
// Install Http.Cache.Headers.MessageHandler as a Cake Addin #addin nuget:?package=Http.Cache.Headers.MessageHandler&version=1.0.1-beta&prerelease // Install Http.Cache.Headers.MessageHandler as a Cake Tool #tool nuget:?package=Http.Cache.Headers.MessageHandler&version=1.0.1-beta&prerelease
Http Cache Headers Message Handler for Http Client
Delegating message handler for Http Client that caches responses using a distributed cache. This handler will cache responses in the following way:
Cheks the response for valid Etag and Cache-Control headers, and caches the response.
The next time the same path is requested, it checks if there is a cache entry and appends Conditional headers to the request. Read here
If the server responds with
NotModified
status code, the response content is replaced with the cached entry.
This message handler is responsible for caching ONLY on the client side. Please check HttpCacheHeaders, an easy to use middleware for supporting cache headers on the server side. The sample in this repo uses this middleware and the tests reference some of the code from there.
Installation (NuGet)
Install-Package Http.Cache.Headers.MessageHandler
Usage
First, register the services with your dependency injection container
services.AddHttpCacheHeadersMessageHandler(options =>
{
options.IgnoreNonGetRequest = true;
options.CacheEntryPrefix = "EtagCachingMessageHandler";
options.CacheKeyHeaderNameExclusions = new[] { "some-auto-generated-header" };
})
You will also need to register a distrubuted cache
services.AddDistributedMemoryCache();
Add the message handler to your http client as follows
services.AddHttpClient<MyHttpClient>()
.AddHttpMessageHandler<HttpCacheHeadersDelegatingHandler>();
Note: the back-end needs to already support http cache headers for this handler to work. Also make sure to header the next section
Header Exclusions
<a name="important"></a>The cache key is generated using a combination of the request path
plus the headers
.
Headers with auto-generated values must be excluded when creating the cache key. If your header gets a new value for every request then it should be excluded
Not excluding these header means the handler will never find your cache entries, and will never append the Conditional headers to the request.
You can exclude these types of headers when registering the services
options.CacheKeyHeaderNameExclusions = new[] { "some-auto-generated-header" };
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.Extensions.Caching.Abstractions (>= 5.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0)
- Newtonsoft.Json (>= 12.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.1-beta-1 | 718 | 8/21/2021 |
1.0.1-beta | 190 | 8/18/2021 |
1.0.0-beta | 188 | 8/16/2021 |
Beta version