try {
// Is the response ready to be cached?
if (tx.isValid() && response.isValid() && response.getStatus() == HttpServletResponse.SC_OK) {
logger.trace("Writing response for {} to the cache", response);
CacheHandle cacheHdl = tx.getHandle();
String encoding = cacheableResponse.getCharacterEncoding();
CacheEntry entry = new CacheEntry(cacheHdl, tx.getContent(), encoding, tx.getHeaders());
Element element = new Element(new CacheEntryKey(cacheHdl), entry);
element.setTimeToLive((int) (cacheHdl.getCacheExpirationTime() / 1000));
cache.put(element);
// Write cache and content relevant headers
writeCacheHeaders(response, entry, true);
writeContentHeaders(response, entry);