Search in sources :

Example 1 with HttpCacheServletResponseWrapper

use of com.adobe.acs.commons.httpcache.engine.HttpCacheServletResponseWrapper in project acs-aem-commons by Adobe-Consulting-Services.

the class HttpCacheEngineImpl method cacheResponse.

@Override
public void cacheResponse(SlingHttpServletRequest request, SlingHttpServletResponse response, HttpCacheConfig cacheConfig) throws HttpCacheKeyCreationException, HttpCacheDataStreamException, HttpCachePersistenceException {
    // TODO - This can be made asynchronous to avoid performance penalty on response cache.
    CacheContent cacheContent = null;
    try {
        // Construct the cache content.
        HttpCacheServletResponseWrapper responseWrapper = null;
        if (response instanceof HttpCacheServletResponseWrapper) {
            responseWrapper = (HttpCacheServletResponseWrapper) response;
        } else {
            throw new AssertionError("Programming error.");
        }
        CacheKey cacheKey = cacheConfig.buildCacheKey(request);
        cacheContent = new CacheContent().build(responseWrapper);
        // Persist in cache.
        if (isRequestCachableAccordingToHandlingRules(request, response, cacheConfig, cacheContent)) {
            getCacheStore(cacheConfig).put(cacheKey, cacheContent);
            log.debug("Response for the URI cached - {}", request.getRequestURI());
        }
    } finally {
        // Close the temp sink input stream.
        if (null != cacheContent) {
            IOUtils.closeQuietly(cacheContent.getInputDataStream());
        }
    }
}
Also used : HttpCacheServletResponseWrapper(com.adobe.acs.commons.httpcache.engine.HttpCacheServletResponseWrapper) CacheContent(com.adobe.acs.commons.httpcache.engine.CacheContent) CacheKey(com.adobe.acs.commons.httpcache.keys.CacheKey)

Aggregations

CacheContent (com.adobe.acs.commons.httpcache.engine.CacheContent)1 HttpCacheServletResponseWrapper (com.adobe.acs.commons.httpcache.engine.HttpCacheServletResponseWrapper)1 CacheKey (com.adobe.acs.commons.httpcache.keys.CacheKey)1