.NET 7.0: Output Caching: Evaluate policy after other middleware processed the request #44191
Open
1 task done
Labels
area-middleware
Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware
area-networking
Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Milestone
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
When providing APIs to be used publicly, some error code like
404
might worth to be cache longer than success code since we know this state won't change anytime soon.In my case, I provide an API to search for subtitle for shows.
The api take the searched show from the URL. It's more than possible that said show isn't available on my service yet.
I return a 404 and like to cache that result for longer than a succesful found show with subtitles.
Describe the solution you'd like
Delay evaluation of policy to when we have a response to let the developer use
HttpContext.Response
as part of rule for matching policy, like its status code.Additional context
Currently we have access to the response using the
.With(context => context.HttpContext.Response.StatusCode == 404);
when defining a policy. The issue is, since the response isn't created yet, the status code is always 200.Since there isn't yet a full documentation of the capabilities of the
With
method, it can leads to unexpected cases.The text was updated successfully, but these errors were encountered: