| Method from org.springframework.web.servlet.support.WebContentGenerator Detail: |
protected final void applyCacheSeconds(HttpServletResponse response,
int seconds) {
applyCacheSeconds(response, seconds, false);
}
Apply the given cache seconds and generate corresponding HTTP headers,
i.e. allow caching for the given number of seconds in case of a positive
value, prevent caching if given a 0 value, do nothing else.
Does not tell the browser to revalidate the resource. |
protected final void applyCacheSeconds(HttpServletResponse response,
int seconds,
boolean mustRevalidate) {
if (seconds > 0) {
cacheForSeconds(response, seconds, mustRevalidate);
}
else if (seconds == 0) {
preventCaching(response);
}
// Leave caching to the client otherwise.
}
Apply the given cache seconds and generate respective HTTP headers.
That is, allow caching for the given number of seconds in the
case of a positive value, prevent caching if given a 0 value, else
do nothing (i.e. leave caching to the client). |
protected final void cacheForSeconds(HttpServletResponse response,
int seconds) {
cacheForSeconds(response, seconds, false);
}
Set HTTP headers to allow caching for the given number of seconds.
Does not tell the browser to revalidate the resource. |
protected final void cacheForSeconds(HttpServletResponse response,
int seconds,
boolean mustRevalidate) {
if (this.useExpiresHeader) {
// HTTP 1.0 header
response.setDateHeader(HEADER_EXPIRES, System.currentTimeMillis() + seconds * 1000L);
}
if (this.useCacheControlHeader) {
// HTTP 1.1 header
String headerValue = "max-age=" + seconds;
if (mustRevalidate) {
headerValue += ", must-revalidate";
}
response.setHeader(HEADER_CACHE_CONTROL, headerValue);
}
}
Set HTTP headers to allow caching for the given number of seconds.
Tells the browser to revalidate the resource if mustRevalidate is
true. |
protected final void checkAndPrepare(HttpServletRequest request,
HttpServletResponse response,
boolean lastModified) throws ServletException {
checkAndPrepare(request, response, this.cacheSeconds, lastModified);
}
Check and prepare the given request and response according to the settings
of this generator. Checks for supported methods and a required session,
and applies the number of cache seconds specified for this generator. |
protected final void checkAndPrepare(HttpServletRequest request,
HttpServletResponse response,
int cacheSeconds,
boolean lastModified) throws ServletException {
// Check whether we should support the request method.
String method = request.getMethod();
if (this.supportedMethods != null && !this.supportedMethods.contains(method)) {
throw new HttpRequestMethodNotSupportedException(
method, StringUtils.toStringArray(this.supportedMethods));
}
// Check whether a session is required.
if (this.requireSession) {
if (request.getSession(false) == null) {
throw new HttpSessionRequiredException("Pre-existing session required but none found");
}
}
// Do declarative cache control.
// Revalidate if the controller supports last-modified.
applyCacheSeconds(response, cacheSeconds, lastModified);
}
Check and prepare the given request and response according to the settings
of this generator. Checks for supported methods and a required session,
and applies the given number of cache seconds. |
public final int getCacheSeconds() {
return this.cacheSeconds;
}
Return the number of seconds that content is cached. |
public final String[] getSupportedMethods() {
return StringUtils.toStringArray(this.supportedMethods);
}
Return the HTTP methods that this content generator supports. |
public final boolean isRequireSession() {
return this.requireSession;
}
Return whether a session is required to handle requests. |
public final boolean isUseCacheControlHeader() {
return this.useCacheControlHeader;
}
Return whether the HTTP 1.1 cache-control header is used. |
public final boolean isUseCacheControlNoStore() {
return this.useCacheControlNoStore;
}
Return whether the HTTP 1.1 cache-control header value "no-store" is used. |
public final boolean isUseExpiresHeader() {
return this.useExpiresHeader;
}
Return whether the HTTP 1.0 expires header is used. |
protected final void preventCaching(HttpServletResponse response) {
response.setHeader(HEADER_PRAGMA, "no-cache");
if (this.useExpiresHeader) {
// HTTP 1.0 header
response.setDateHeader(HEADER_EXPIRES, 1L);
}
if (this.useCacheControlHeader) {
// HTTP 1.1 header: "no-cache" is the standard value,
// "no-store" is necessary to prevent caching on FireFox.
response.setHeader(HEADER_CACHE_CONTROL, "no-cache");
if (this.useCacheControlNoStore) {
response.addHeader(HEADER_CACHE_CONTROL, "no-store");
}
}
}
Prevent the response from being cached.
See http://www.mnot.net/cache_docs. |
public final void setCacheSeconds(int seconds) {
this.cacheSeconds = seconds;
}
Cache content for the given number of seconds. Default is -1,
indicating no generation of cache-related headers.
Only if this is set to 0 (no cache) or a positive value (cache for
this many seconds) will this class generate cache headers.
The headers can be overwritten by subclasses, before content is generated. |
public final void setRequireSession(boolean requireSession) {
this.requireSession = requireSession;
}
Set whether a session should be required to handle requests. |
public final void setSupportedMethods(String[] methods) {
if (methods != null) {
this.supportedMethods = new HashSet(Arrays.asList(methods));
}
else {
this.supportedMethods = null;
}
}
Set the HTTP methods that this content generator should support.
Default is HEAD, GET and POST. |
public final void setUseCacheControlHeader(boolean useCacheControlHeader) {
this.useCacheControlHeader = useCacheControlHeader;
}
Set whether to use the HTTP 1.1 cache-control header. Default is "true".
Note: Cache headers will only get applied if caching is enabled
(or explicitly prevented) for the current request. |
public final void setUseCacheControlNoStore(boolean useCacheControlNoStore) {
this.useCacheControlNoStore = useCacheControlNoStore;
}
Set whether to use the HTTP 1.1 cache-control header value "no-store"
when preventing caching. Default is "true". |
public final void setUseExpiresHeader(boolean useExpiresHeader) {
this.useExpiresHeader = useExpiresHeader;
}
Set whether to use the HTTP 1.0 expires header. Default is "true".
Note: Cache headers will only get applied if caching is enabled
(or explicitly prevented) for the current request. |