CSSCacheIdentity identity = new CSSCacheIdentity(base64Key);
if (logger.isDebugEnabled()) {
logger.debug("Key createTime is " + identity.getCreateTime());
logger.debug("Key sequenceNo is " + identity.getSequenceNo());
}
CSSCacheEntry entity = (CSSCacheEntry) cssCache.retrieve(identity);
if (entity != null) {
response.setContentType("text/css");
// Set caching HTTP headers.
long nowTime = System.currentTimeMillis();
long createTime = identity.getCreateTime();
long expiresTime = identity.getExpiresTime();
// Calculate max-age, avoiding negative values.
long maxAgeSeconds = Math.max ((expiresTime - nowTime) / 1000, 0);
// Set HTTP 1.1 headers
response.addHeader("Cache-Control", "max-age=" + maxAgeSeconds);
// Set HTTP 1.0 headers
response.setDateHeader("Date", createTime);
response.setDateHeader("Expires", expiresTime);
// Write HTTP contents
PrintWriter out = response.getWriter();
entity.getCacheObjectAsWritableCSSEntity().write(out);
out.close();
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}