Search in sources :

Example 11 with CacheKey

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

the class EntryNodeToCacheKeyHandler method get.

public CacheKey get() throws RepositoryException, IOException, ClassNotFoundException {
    if (entryNode != null) {
        final Property cacheKeyProperty = entryNode.getProperty(JCRHttpCacheStoreConstants.PN_CACHEKEY);
        final InputStream inputStream = cacheKeyProperty.getBinary().getStream();
        final ClassLoader dynamicClassLoader = dynamicClassLoaderManager.getDynamicClassLoader();
        final DynamicObjectInputStream dynamicObjectInputStream = new DynamicObjectInputStream(inputStream, dynamicClassLoader);
        return (CacheKey) dynamicObjectInputStream.readObject();
    }
    return null;
}
Also used : DynamicObjectInputStream(com.adobe.acs.commons.util.DynamicObjectInputStream) DynamicObjectInputStream(com.adobe.acs.commons.util.DynamicObjectInputStream) InputStream(java.io.InputStream) Property(javax.jcr.Property) CacheKey(com.adobe.acs.commons.httpcache.keys.CacheKey)

Example 12 with CacheKey

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

the class InvalidateByCacheConfigVisitor method leaving.

protected void leaving(final Node node, int level) throws RepositoryException {
    if (isCacheEntryNode(node)) {
        // check and remove nodes that are expired.
        try {
            final CacheKey key = getCacheKey(node);
            if (cacheConfig.knows(key)) {
                node.remove();
                persistSession();
            }
        } catch (Exception e) {
            log.error("Exception occured in retrieving the CacheKey from the entry node", e);
            throw new RepositoryException(e);
        }
    } else if (isEmptyBucketNode(node)) {
        // cleanup empty bucket nodes.
        node.remove();
        persistSession();
    }
    super.leaving(node, level);
}
Also used : RepositoryException(javax.jcr.RepositoryException) CacheKey(com.adobe.acs.commons.httpcache.keys.CacheKey) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Example 13 with CacheKey

use of com.adobe.acs.commons.httpcache.keys.CacheKey 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

CacheKey (com.adobe.acs.commons.httpcache.keys.CacheKey)13 CacheContent (com.adobe.acs.commons.httpcache.engine.CacheContent)6 Node (javax.jcr.Node)6 RootNodeMockFactory (com.adobe.acs.commons.httpcache.store.jcr.impl.visitor.mock.RootNodeMockFactory)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 HttpCacheConfig (com.adobe.acs.commons.httpcache.config.HttpCacheConfig)2 IOException (java.io.IOException)2 RepositoryException (javax.jcr.RepositoryException)2 DynamicClassLoaderManager (org.apache.sling.commons.classloader.DynamicClassLoaderManager)2 HttpCacheServletResponseWrapper (com.adobe.acs.commons.httpcache.engine.HttpCacheServletResponseWrapper)1 DynamicObjectInputStream (com.adobe.acs.commons.util.DynamicObjectInputStream)1 InputStream (java.io.InputStream)1 NodeIterator (javax.jcr.NodeIterator)1 Property (javax.jcr.Property)1