Skip to content

Response Caching Middleware — Config Cache-Control max-age per Content-Type #3361

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
ghost opened this issue Jul 26, 2018 · 5 comments
Closed
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares feature-response-caching

Comments

@ghost
Copy link

ghost commented Jul 26, 2018

How, with Response Caching in Middleware, can we configure:

  • Cache-Control 's max-age per Content-Type?
  • Override cache policy by Location?

With Microsoft.AspNetCore.Builder.StaticFileOptions, we can use if/else/switch, but how to do the same thing with Microsoft.Net.Http.Headers.CacheControlHeaderValue()

@Tratcher
Copy link
Member

@JunTaoLuo

@JunTaoLuo
Copy link
Contributor

We don't currently have any functionality like StaticFileOptions's OnPrepareResponse where you can directly modify the response that's being sent by the middleware. This feature is tracked in #2618.

However, you can achieve a similar effect by setting the Vary header to "Content-Type, Location" and storing multiple responses. See https://docs.microsoft.com/en-us/aspnet/core/performance/caching/middleware?view=aspnetcore-2.1#http-headers-used-by-response-caching-middleware for an explanation.

@ghost
Copy link
Author

ghost commented Jul 27, 2018

@JunTaoLuo

However, you can achieve a similar effect by setting the Vary header to "Content-Type, Location" and storing multiple responses.

Similar effect? Can you show me how to store multiple responses with different MaxAge?

@JunTaoLuo
Copy link
Contributor

Ah, I mis-spoke. The Vary header will only allow the storing of multiple responses for different values of Request headers. However, in your scenario, you want to set different max-age based on the Content-Type of the Response right? That's not possible at the moment and the feature in the previous link would need to be implemented to enable this. The same goes for Location. The functionality of the response cache middleware is currently very limited so you may need to set the appropriate headers and rely on the caching performed by the browser and intermediaries like proxies.

@ghost
Copy link
Author

ghost commented Jul 27, 2018

Ok thanks!

@ghost ghost closed this as completed Jul 27, 2018
@ghost ghost locked as resolved and limited conversation to collaborators Jun 1, 2021
@amcasey amcasey added the area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares label Jun 2, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares feature-response-caching
Projects
None yet
Development

No branches or pull requests

3 participants