From 140fd0eb8b82e924652d7bce3510659f0f47854a Mon Sep 17 00:00:00 2001 From: j2blake Date: Mon, 3 Jun 2013 15:44:17 -0400 Subject: [PATCH] VIVO-117 Turn off HTTP caching unless explicitly enabled in runtime.properties. --- doc/install.html | 20 +++++++++++++++++++ webapp/config/example.runtime.properties | 13 ++++++++++++ .../webapp/filters/CachingResponseFilter.java | 19 +++++++++++++----- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/doc/install.html b/doc/install.html index f3baf7702..6121d15a6 100644 --- a/doc/install.html +++ b/doc/install.html @@ -649,6 +649,26 @@ remote_userID + + + + Tell Vitro to generate HTTP headers on its responses to facilitate caching the + profile pages that it creates. This can improve performance, but it can also + result in serving stale data. Default is false if not set. + For more information, see the VIVO wiki page: + + Use HTTP caching to improve performance + + + + + http.createCacheHeaders + + + true + + + Force VIVO to use a specific language or Locale instead of those diff --git a/webapp/config/example.runtime.properties b/webapp/config/example.runtime.properties index 3802063d2..c91188ae3 100644 --- a/webapp/config/example.runtime.properties +++ b/webapp/config/example.runtime.properties @@ -120,6 +120,19 @@ proxy.eligibleTypeList = http://www.w3.org/2002/07/owl#Thing # RDFService.languageFilter = true +# +# Tell VIVO to generate HTTP headers on its responses to facilitate caching the +# profile pages that it creates. +# +# For more information, see +# https://wiki.duraspace.org/display/VIVO/Use+HTTP+caching+to+improve+performance +# +# Developers will likely want to leave caching disabled, since a change to a +# Freemarker template or to a Java class would not cause the page to be +# considered stale. +# +# http.createCacheHeaders = true + # # Force VIVO to use a specific language or Locale instead of those # specified by the browser. This affects RDF data retrieved from the model, diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/CachingResponseFilter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/CachingResponseFilter.java index 9fc4186a7..26c8e452d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/CachingResponseFilter.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/CachingResponseFilter.java @@ -37,6 +37,8 @@ import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrResultsParser; /** * Assist in cache management for individual profile pages. * + * Must be enabled in runtime.properties. + * * Only works for users who are not logged in. * * The Solr index must be configured to keep an ETAG on each individual's @@ -72,6 +74,7 @@ public class CachingResponseFilter implements Filter { .getLog(CachingResponseFilter.class); private static final String PROPERTY_DEFAULT_NAMESPACE = "Vitro.defaultNamespace"; + private static final String PROPERTY_ENABLE_CACHING = "http.createCacheHeaders"; private static final String ETAG_FIELD = "etag"; private static final FieldMap parserFieldMap = SolrQueryUtils.fieldMap() @@ -79,12 +82,14 @@ public class CachingResponseFilter implements Filter { private ServletContext ctx; private String defaultNamespace; + private boolean enabled; @Override public void init(FilterConfig fc) throws ServletException { ctx = fc.getServletContext(); - defaultNamespace = ConfigurationProperties.getBean(ctx).getProperty( - PROPERTY_DEFAULT_NAMESPACE); + ConfigurationProperties props = ConfigurationProperties.getBean(ctx); + defaultNamespace = props.getProperty(PROPERTY_DEFAULT_NAMESPACE); + enabled = Boolean.valueOf(props.getProperty(PROPERTY_ENABLE_CACHING)); } @Override @@ -102,10 +107,14 @@ public class CachingResponseFilter implements Filter { HttpServletResponse resp = (HttpServletResponse) response; /* - * If this request is not for a profile page, or if the individual - * doesn't appear in the search index, create a basic, cache-neutral - * response. + * If caching is disabled, if this request is not for a profile page, or + * if the individual doesn't appear in the search index, create a basic, + * cache-neutral response. */ + if (!enabled) { + produceBasicResponse(req, resp, chain); + return; + } String individualUri = figureIndividualUriFromRequest(req); if (individualUri == null) { produceBasicResponse(req, resp, chain);