-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Provide controller method level alternative to WebContentInterceptor [SPR-8550] #13194
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
Comments
Rossen Stoyanchev commented This would be useful in cases where configuring an interceptor is not ideal (e.g. a framework built on Spring MVC). For Spring MVC applications WebContentInterceptor should be sufficient and more centralized. Instead of |
Felix Barnsteiner commented I would suggest to do this simmilar to JAX-RS 2.0: http://jax-rs-spec.java.net/nonav/2.0-SNAPSHOT/apidocs/javax/ws/rs/core/CacheControl.html |
Rossen Stoyanchev commented I've updated the title (was: "Declarative cache policy for |
Brian Clozel commented There are now several ways to handle HTTP caching at the controller level:
This is described in the dedicated section of the reference documentation. See #16413 for more details. |
Michael Osipov commented I fail to see how this was reasonably resolved. There is no annotation for this. Using |
Brian Clozel commented Here is my current understanding about this:
Now we were considering There are also other ways to globally alter those cache directives (by using What are you missing with the current model? |
Corey Engelman commented Hi, Just curious if the change from outputMessage.getBody() to outputMessage.flush() was intentional? This has a potential to have a pretty large impact. For example if using a javax.servlet.Filter, you cannot make any changes to the response body/headers after calling FilterChain.doFilter, because the flush() call commits the ServeltResponse/forces it to be writtent to the client. If it was intentional and developers shouldn't be doing that (ie everything must be set before calling doFilter), then thats fine, but just wanted to confirm if this is desired behavior, especially since I am not sure exactly how it relates to the issue tracked by this ticket. FWIW this was an issue discovered when upgrading from spring 4.1.x -> 4.3.x line in question - Line 156 in f9ce11e
commit - f9ce11e Any help would be greatly appreciated |
Brian Clozel commented Hi Corey Engelman, What you're describing is not specific to this commit at all. In general, you should consider that once calling Spring Framework is using a |
Corey Engelman commented Thanks for clarifying. I can update the code on my end to assume the response could be committed by doFilter(). Is it worth noting that anyone else who incorrectly made the assumption that it was ok to try to modify headers after doFilter() will also have similar issues? I guess my main point is: whether the code on my end is incorrect or not, it worked with spring 4.1.x and does not work with spring 4.2.x and beyond. Not sure if there is a preferred place to put such notes so other developers don't run into the same issue when upgrading. Either way, thanks again, this is very helpful (y) |
Rossen Stoyanchev commented Note that you can use |
Craig Walls opened SPR-8550 and commented
Even though WebContentInterceptor can be used to declare when and how cache-control headers are set in a response, it isn't as straightforward or consistent with the
@Controller
model.I propose an annotation-based option for declaring when cache-control headers are added to a response. For example, a general-purpose
@CachePolicy
annotation might be used like this:Also, perhaps a more specific-purpose
@PreventCaching
annotation might declare that a response include the headers currently added by WebContentGenerator's preventCaching() method.These two annotations are just suggestions--I'd be interested in any solution that allows for declarative cache policies at the request method level.
Affects: 3.0.6
This issue is a sub-task of #16413
Issue Links:
Referenced from: commits f9ce11e
10 votes, 17 watchers
The text was updated successfully, but these errors were encountered: