}
// handle caching
try {
ICacheEntry ce = cache.get(request, minFresh);
if ((ce != null) && !(ce.isAfter(maxOld))) {
// must revalidate?
if (ce.mustRevalidate(minFresh)) {
if (isOnlyIfCached) {
countCacheMiss++;
statistics.addMiss();
exchange.sendError(504);
} else {
IValidationHandler validationHdl = new IValidationHandler() {
public void onRevalidated(boolean isNotModified, HttpCache.AbstractCacheEntry ce) {
if (isNotModified) {
try {
countCacheHit++;
statistics.addHit();
IHttpResponse resp = ce.newResponse();
resp.setHeader(XHEADER_NAME, "HIT - revalidated (xLightweb)");
resp.setAttribute(CACHE_HIT, "HIT (revalidated)");
exchange.send(resp);
} catch (IOException ioe) {
exchange.sendError(ioe);
}
} else {
try {
countCacheMiss++;
statistics.addMiss();
IHttpResponse resp = ce.newResponse();
exchange.send(resp);
} catch (IOException ioe) {
exchange.sendError(ioe);
}
}
}
public void onException(IOException ioe) {
exchange.sendError(ioe);
}
};
ce.revalidate(exchange, validationHdl);
}
// .. revalidation is not required
} else {
countCacheHit++;
statistics.addHit();
IHttpResponse resp = ce.newResponse();
resp.setHeader(XHEADER_NAME, "HIT (xLightweb)");
resp.setAttribute(CACHE_HIT, "HIT");
exchange.send(resp);
}