|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2012 the original author or authors. |
| 2 | + * Copyright 2002-2013 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
26 | 26 | import org.springframework.util.StringUtils;
|
27 | 27 | import org.springframework.web.HttpRequestMethodNotSupportedException;
|
28 | 28 | import org.springframework.web.HttpSessionRequiredException;
|
| 29 | +import org.springframework.web.context.request.WebRequest; |
29 | 30 | import org.springframework.web.context.support.WebApplicationObjectSupport;
|
| 31 | +import org.springframework.web.servlet.mvc.LastModified; |
30 | 32 |
|
31 | 33 | /**
|
32 | 34 | * Convenient superclass for any kind of web content generator,
|
@@ -79,6 +81,8 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
|
79 | 81 |
|
80 | 82 | private int cacheSeconds = -1;
|
81 | 83 |
|
| 84 | + private boolean alwaysMustRevalidate = false; |
| 85 | + |
82 | 86 |
|
83 | 87 | /**
|
84 | 88 | * Create a new WebContentGenerator which supports
|
@@ -194,6 +198,25 @@ public final boolean isUseCacheControlNoStore() {
|
194 | 198 | return this.useCacheControlNoStore;
|
195 | 199 | }
|
196 | 200 |
|
| 201 | + /** |
| 202 | + * An option to add 'must-revalidate' to every Cache-Control header. This |
| 203 | + * may be useful with annotated controller methods, which can |
| 204 | + * programmatically do a lastModified calculation as described in |
| 205 | + * {@link WebRequest#checkNotModified(long)}. Default is "false", |
| 206 | + * effectively relying on whether the handler implements |
| 207 | + * {@link LastModified} or not. |
| 208 | + */ |
| 209 | + public void setAlwaysMustRevalidate(boolean mustRevalidate) { |
| 210 | + this.alwaysMustRevalidate = mustRevalidate; |
| 211 | + } |
| 212 | + |
| 213 | + /** |
| 214 | + * Return whether 'must-revaliate' is added to every Cache-Control header. |
| 215 | + */ |
| 216 | + public boolean isAlwaysMustRevalidate() { |
| 217 | + return alwaysMustRevalidate; |
| 218 | + } |
| 219 | + |
197 | 220 | /**
|
198 | 221 | * Cache content for the given number of seconds. Default is -1,
|
199 | 222 | * indicating no generation of cache-related headers.
|
@@ -313,7 +336,7 @@ protected final void cacheForSeconds(HttpServletResponse response, int seconds,
|
313 | 336 | if (this.useCacheControlHeader) {
|
314 | 337 | // HTTP 1.1 header
|
315 | 338 | String headerValue = "max-age=" + seconds;
|
316 |
| - if (mustRevalidate) { |
| 339 | + if (mustRevalidate || this.alwaysMustRevalidate) { |
317 | 340 | headerValue += ", must-revalidate";
|
318 | 341 | }
|
319 | 342 | response.setHeader(HEADER_CACHE_CONTROL, headerValue);
|
|
0 commit comments