try {
ThreadContext.getDependencyMap().beginTransaction(true);
ThreadContext c = ThreadContext.get();
HttpServletRequest request = c.getServletRequest();
HttpServletResponse response = c.getServletResponse();
Cache cache = ThreadContext.getCache();
String cacheURL = c.getRequestURL();
Response cachedResponse = cache.get(cacheURL);
if (cachedResponse == null) {
String augmentationString = "<|>"
+ WebApp.get().getWebSite()
.getCacheAugmentationString();
cacheURL = c.getRequestURL() + augmentationString;
cachedResponse = cache.get(cacheURL);
}
if (cachedResponse != null) {
String cacheControl = request.getHeader("cache-control");
long if_modified_since = -1;
try {
if_modified_since = request
.getDateHeader("If-Modified-Since");
} catch (IllegalArgumentException e) {
log.info("Client sent invalid If-Modified-Since");
}
try {
String if_none_match = request.getHeader("If-None-Match");
long lastModified = (cachedResponse.getLastModified() / 1000) * 1000;
long ifModifiedSince = (if_modified_since / 1000) * 1000;
if (if_none_match == null && if_modified_since == -1
&& cacheControl != null
&& cacheControl.equals("max-age=0")) {
log.info("Client refreshed the page. Removing the old one from the cache");
cache.remove(cacheURL);
} else {
if ((if_none_match != null && if_none_match.equals("\""
+ cachedResponse.getETag() + "\""))
|| (if_none_match == null