VIVO-117 Turn off HTTP caching unless explicitly enabled in runtime.properties.
This commit is contained in:
parent
2134981110
commit
140fd0eb8b
3 changed files with 47 additions and 5 deletions
|
@ -649,6 +649,26 @@
|
|||
remote_userID
|
||||
</td>
|
||||
</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>
|
||||
<td colspan="2">
|
||||
Force VIVO to use a specific language or Locale instead of those
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue