VIVO-117 Turn off HTTP caching unless explicitly enabled in runtime.properties.

This commit is contained in:
j2blake 2013-06-03 15:44:17 -04:00
parent 2134981110
commit 140fd0eb8b
3 changed files with 47 additions and 5 deletions

View file

@ -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,

View file

@ -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);