Enable/Enhance response caching using Etag Filter for Minimal APIs endpoints #39429
Labels
old-area-web-frameworks-do-not-use
*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
triage-focus
Add this label to flag the issue for focus at triage
Milestone
Summary
ASPNET Core provides
builder.Services.AddResponseCaching
in combination withapp.UseResponseCaching()
as a way to cache responses for both controllers with views and Web APIs. This type of response caching relies on the client sending headers likeCache-Control
,Pragma
,If-None-Match
, etc.We, however, do not provide a way to generate some of the headers that need to be generated at the server side. One of them is the Etag value that gets used in
If-None-Match
header to uniquely identify the resource (entity, etc.) lifetime on the server. For example, if a resource at a certain endpoint changes, a new Etag value must be generated and compared with the value that the client sent in theIf-None-Match
header. If the two values do not match, the server sends a new fresh copy of the entity/resource and the new Etag value, otherwise the server replies with a304 Not Modified
response status without a body to indicate that the client copy of the cached resource is still good to use. This is one of the ways to cache responses and prevent the resource result from being sent to the client (Written to Response Stream).It will be nice to provide a filter out of the box to allow customers to customize Etag generations.
We should also consider providing an option to set the preferred hashing algorithm (SHA256, MD5, etc.).
This only applies to "GET" Http method.
Motivation and goals
Provide an out of the box solution (Filter) for users to generate Etag values based on the response content. The Etag header subsequently gets used in
If-None-Match
header for response caching. This will result in saving response bandwidth.Risks / unknowns
To be able to provide this type of functionality at the endpoint level, we will need to enable filters for Minimal APIs. Potentially, if the user can have access to the endpoint response content through a filter, we could let customers implement this functionality themselves.
Examples
There are other frameworks like Spring and Fiber that provide Etag filters/implementations out of the box. See links below
The text was updated successfully, but these errors were encountered: