diff options
Diffstat (limited to 'src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java')
-rw-r--r-- | src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index 83310a943b..092fde21ff 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -182,7 +182,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements private boolean productionMode = false; - private String resourcePath = null; + private final String resourcePath = null; + + private int resourceCacheTime = 3600; /** * Called by the servlet container to indicate to a servlet that the servlet @@ -220,6 +222,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements } checkProductionMode(); checkCrossSiteProtection(); + checkResourceCacheTime(); } private void checkCrossSiteProtection() { @@ -254,6 +257,19 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements } + private void checkResourceCacheTime() { + // Check if the browser caching time has been set in web.xml + try { + String rct = getApplicationOrSystemProperty( + SERVLET_PARAMETER_RESOURCE_CACHE_TIME, "3600"); + resourceCacheTime = Integer.parseInt(rct); + } catch (NumberFormatException nfe) { + // Default is 1h + resourceCacheTime = 3600; + System.err.println(WARNING_RESOURCE_CACHING_TIME_NOT_NUMERIC); + } + } + /** * Gets an application property value. * @@ -344,6 +360,16 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements } /** + * Returns the amount of milliseconds the browser should cache a file. + * Default is 1 hour (3600 ms). + * + * @return The amount of milliseconds files are cached in the browser + */ + public int getResourceCacheTime() { + return resourceCacheTime; + } + + /** * Receives standard HTTP requests from the public service method and * dispatches them. * @@ -1181,9 +1207,12 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements * the file has changed. This forces browsers to fetch a new version * when the Vaadin version is updated. This will cause more requests * to the servlet than without this but for high volume sites the - * static files should never be served through the servlet. + * static files should never be served through the servlet. The + * cache timeout can be configured by setting the resourceCacheTime + * parameter in web.xml */ - response.setHeader("Cache-Control", "max-age: 3600"); + response.setHeader("Cache-Control", "max-age: " + + String.valueOf(resourceCacheTime)); } // Write the resource to the client. |