Timer timer = new Timer(getCachedUri(request));
timer.start();
String key = calculateKey(request);
PageInfo pageInfo;
try {
// Page is not cached - build the response, cache it, and send to client
pageInfo = buildPage(request, response, chain);
if (pageInfo.isOk()) {
Object noCache = pageInfo.getCacheDirectives().get("no-cache");
if (noCache instanceof Boolean && ((Boolean)noCache)) {
log.debug("Response ok but Cache-Control: no-cache is present, not caching");
releaseCacheLocks(operationsByType, key);
}
else {
Collection<Cache> caches = new ArrayList<Cache>();
for (CacheOperationContext operationContext : operationsByType.get(UPDATE)) {
for (Cache cache : operationContext.getCaches()) {
caches.add(cache);
}
}
update(caches, pageInfo, cacheStatus, key);
}
}
else {
for (CacheOperationContext operationContext : operationsByType.get(UPDATE)) {
for (Cache cache : operationContext.getCaches()) {
log.debug("Response not ok ({}). Putting null into cache {} with key {}",
new Object[] { pageInfo.getStatusCode(), cache.getName(), key } );
}
}
releaseCacheLocks(operationsByType, key);
}
}