}
// handle caching
try {
CacheEntry ce = cache.get(request, minFresh);
// is cache entry valid?
if (ce != null) {
if ((maxOld != null) && (ce.isAfter(maxOld))) {
forwardForCache(exchange);
return;
}
// must revalidate?
if (ce.mustRevalidate(minFresh)) {
if (isOnlyIfCached) {
countCacheMiss++;
exchange.sendError(504);
} else {
IValidationHandler validationHdl = new IValidationHandler() {
public void onRevalidated(boolean isNotModified, CacheEntry ce) {
if (isNotModified) {
try {
countCacheHit++;
IHttpResponse resp = ce.newResponse();
resp.setHeader(XHEADER_NAME, "HIT - revalidated (xLightweb)");
exchange.send(resp);
} catch (IOException ioe) {
exchange.sendError(ioe);
}
} else {
try {
countCacheMiss++;
IHttpResponse resp = ce.newResponse();
exchange.send(resp);
} catch (IOException ioe) {
exchange.sendError(ioe);
}
}
}
public void onException(IOException ioe) {
exchange.sendError(ioe);
}
};
ce.revalidate(validationHdl);
}
// no, return cached response
} else {
countCacheHit++;
IHttpResponse resp = ce.newResponse();
resp.setHeader(XHEADER_NAME, "HIT (xLightweb)");
exchange.send(resp);
}