SWF-921 Allow setting of cache seconds in ResourceServlet
Introduced 'cacheTimeout' property as the number of seconds to cache. Setting to zero disabled caching.
This commit is contained in:
@@ -47,6 +47,7 @@ import org.springframework.web.servlet.HttpServletBean;
|
||||
* Special resource servlet for efficiently resolving and rendering static resources from within a JAR file.
|
||||
*
|
||||
* @author Jeremy Grelle
|
||||
* @author Scott Andrews
|
||||
*/
|
||||
public class ResourceServlet extends HttpServletBean {
|
||||
|
||||
@@ -100,6 +101,8 @@ public class ResourceServlet extends HttpServletBean {
|
||||
compressedMimeTypes.add("text/*");
|
||||
}
|
||||
|
||||
private int cacheTimeout = 31556926;
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
String rawResourcePath = request.getPathInfo();
|
||||
@@ -196,7 +199,9 @@ public class ResourceServlet extends HttpServletBean {
|
||||
response.setContentType(mimeType);
|
||||
response.setHeader(HTTP_CONTENT_LENGTH_HEADER, Long.toString(contentLength));
|
||||
response.setDateHeader(HTTP_LAST_MODIFIED_HEADER, lastModified);
|
||||
configureCaching(response, 31556926);
|
||||
if (cacheTimeout > 0) {
|
||||
configureCaching(response, cacheTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
protected long getLastModified(HttpServletRequest request) {
|
||||
@@ -410,4 +415,12 @@ public class ResourceServlet extends HttpServletBean {
|
||||
public void setJarPathPrefix(String jarPathPrefix) {
|
||||
this.jarPathPrefix = jarPathPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of seconds resources should be cached by the client. Zero disables caching. Default is one year.
|
||||
*/
|
||||
public void setCacheTimeout(int cacheTimeout) {
|
||||
this.cacheTimeout = cacheTimeout;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user