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

@ -649,6 +649,26 @@
remote_userID remote_userID
</td> </td>
</tr> </tr>
<tr>
<td colspan="2">
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:
<a href="https://wiki.duraspace.org/display/VIVO/Use+HTTP+caching+to+improve+performance">
Use HTTP caching to improve performance </a>
</td>
</tr>
<tr class="odd_row">
<td>
http.createCacheHeaders
</td>
<td>
true
</td>
</tr>
<tr> <tr>
<td colspan="2"> <td colspan="2">
Force VIVO to use a specific language or Locale instead of those Force VIVO to use a specific language or Locale instead of those

View file

@ -120,6 +120,19 @@ proxy.eligibleTypeList = http://www.w3.org/2002/07/owl#Thing
# #
RDFService.languageFilter = true 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 # Force VIVO to use a specific language or Locale instead of those
# specified by the browser. This affects RDF data retrieved from the model, # 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. * Assist in cache management for individual profile pages.
* *
* Must be enabled in runtime.properties.
*
* Only works for users who are not logged in. * Only works for users who are not logged in.
* *
* The Solr index must be configured to keep an ETAG on each individual's * 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); .getLog(CachingResponseFilter.class);
private static final String PROPERTY_DEFAULT_NAMESPACE = "Vitro.defaultNamespace"; 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 String ETAG_FIELD = "etag";
private static final FieldMap parserFieldMap = SolrQueryUtils.fieldMap() private static final FieldMap parserFieldMap = SolrQueryUtils.fieldMap()
@ -79,12 +82,14 @@ public class CachingResponseFilter implements Filter {
private ServletContext ctx; private ServletContext ctx;
private String defaultNamespace; private String defaultNamespace;
private boolean enabled;
@Override @Override
public void init(FilterConfig fc) throws ServletException { public void init(FilterConfig fc) throws ServletException {
ctx = fc.getServletContext(); ctx = fc.getServletContext();
defaultNamespace = ConfigurationProperties.getBean(ctx).getProperty( ConfigurationProperties props = ConfigurationProperties.getBean(ctx);
PROPERTY_DEFAULT_NAMESPACE); defaultNamespace = props.getProperty(PROPERTY_DEFAULT_NAMESPACE);
enabled = Boolean.valueOf(props.getProperty(PROPERTY_ENABLE_CACHING));
} }
@Override @Override
@ -102,10 +107,14 @@ public class CachingResponseFilter implements Filter {
HttpServletResponse resp = (HttpServletResponse) response; HttpServletResponse resp = (HttpServletResponse) response;
/* /*
* If this request is not for a profile page, or if the individual * If caching is disabled, if this request is not for a profile page, or
* doesn't appear in the search index, create a basic, cache-neutral * if the individual doesn't appear in the search index, create a basic,
* response. * cache-neutral response.
*/ */
if (!enabled) {
produceBasicResponse(req, resp, chain);
return;
}
String individualUri = figureIndividualUriFromRequest(req); String individualUri = figureIndividualUriFromRequest(req);
if (individualUri == null) { if (individualUri == null) {
produceBasicResponse(req, resp, chain); produceBasicResponse(req, resp, chain);