Skip to content

Enable/Enhance response caching using Etag Filter for Minimal APIs endpoints #39429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Tracked by #39327
rafikiassumani-msft opened this issue Jan 11, 2022 · 4 comments
Closed
Tracked by #39327
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

Comments

@rafikiassumani-msft
Copy link
Contributor

rafikiassumani-msft commented Jan 11, 2022

Summary

ASPNET Core provides builder.Services.AddResponseCaching in combination with app.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 like Cache-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 the If-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 a 304 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

@rafikiassumani-msft rafikiassumani-msft added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Jan 11, 2022
@rafikiassumani-msft rafikiassumani-msft added this to the .NET 7 Planning milestone Jan 11, 2022
@ghost
Copy link

ghost commented Jan 11, 2022

Thanks for contacting us.

We're moving this issue to the .NET 7 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@rafikiassumani-msft rafikiassumani-msft added the triage-focus Add this label to flag the issue for focus at triage label Jan 11, 2022
@rafikiassumani-msft rafikiassumani-msft changed the title Enable/Enhance response caching for different Minimal APIs scenarios Enable/Enhance response caching using Etag Filter for Minimal APIs endpoints Jan 11, 2022
@sebastienros
Copy link
Member

#40226

@rafikiassumani-msft
Copy link
Contributor Author

Will be covered by #40226

@ghost
Copy link

ghost commented Jun 14, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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
Projects
None yet
Development

No branches or pull requests

2 participants