Search in sources :

Example 1 with HttpCacheDataStreamException

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

the class JCRHttpCacheStoreImpl method put.

@Override
public void put(final CacheKey key, final CacheContent content) throws HttpCacheDataStreamException {
    final long currentTime = System.currentTimeMillis();
    incrementLoadCount();
    withSession(new Consumer<Session>() {

        @Override
        public void accept(Session session) throws Exception {
            final BucketNodeFactory factory = new BucketNodeFactory(session, cacheRootPath, key, bucketTreeDepth);
            final Node bucketNode = factory.getBucketNode();
            final Node entryNode = new BucketNodeHandler(bucketNode, dclm).createOrRetrieveEntryNode(key);
            new EntryNodeWriter(session, entryNode, key, content, expireTimeInSeconds).write();
            session.save();
            incrementLoadSuccessCount();
            incrementTotalLoadTime(System.currentTimeMillis() - currentTime);
        }
    }, new Consumer<Exception>() {

        @Override
        public void accept(Exception e) throws Exception {
            incrementLoadExceptionCount();
        }
    });
}
Also used : BucketNodeFactory(com.adobe.acs.commons.httpcache.store.jcr.impl.writer.BucketNodeFactory) Node(javax.jcr.Node) CacheMBeanException(com.adobe.acs.commons.util.impl.exception.CacheMBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) HttpCacheDataStreamException(com.adobe.acs.commons.httpcache.exception.HttpCacheDataStreamException) OpenDataException(javax.management.openmbean.OpenDataException) IOException(java.io.IOException) BucketNodeHandler(com.adobe.acs.commons.httpcache.store.jcr.impl.handler.BucketNodeHandler) Session(javax.jcr.Session) EntryNodeWriter(com.adobe.acs.commons.httpcache.store.jcr.impl.writer.EntryNodeWriter)

Example 2 with HttpCacheDataStreamException

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

the class MemCachePersistenceObject method buildForCaching.

/**
 * Construct a Mem cache value suitable for caching. This constructor takes deep copy of parameters making the
 * object suitable for caching avoiding any memory leaks.
 *
 * @param charEncoding
 * @param contentType
 * @param headers
 * @param dataInputStream
 * @throws HttpCacheDataStreamException
 */
public MemCachePersistenceObject buildForCaching(int status, String charEncoding, String contentType, Map<String, List<String>> headers, InputStream dataInputStream) throws HttpCacheDataStreamException {
    this.status = status;
    this.charEncoding = charEncoding;
    this.contentType = contentType;
    // Iterate headers and take a copy.
    this.headers = HashMultimap.create();
    for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
        for (String value : entry.getValue()) {
            if (!"Sling-Tracer-Protocol-Version".equals(entry.getKey()) && !"Sling-Tracer-Request-Id".equals(entry.getKey())) {
                // Do NOT cache Sling Tracer headers as this makes debugging difficult and confusing!
                this.headers.put(entry.getKey(), value);
            }
        }
    }
    // Read input stream and place it in a byte array.
    try {
        this.bytes = IOUtils.toByteArray(dataInputStream);
    } catch (IOException e) {
        throw new HttpCacheDataStreamException("Unable to get byte array out of stream", e);
    }
    return this;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) HttpCacheDataStreamException(com.adobe.acs.commons.httpcache.exception.HttpCacheDataStreamException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HttpCacheDataStreamException (com.adobe.acs.commons.httpcache.exception.HttpCacheDataStreamException)2 IOException (java.io.IOException)2 BucketNodeHandler (com.adobe.acs.commons.httpcache.store.jcr.impl.handler.BucketNodeHandler)1 BucketNodeFactory (com.adobe.acs.commons.httpcache.store.jcr.impl.writer.BucketNodeFactory)1 EntryNodeWriter (com.adobe.acs.commons.httpcache.store.jcr.impl.writer.EntryNodeWriter)1 CacheMBeanException (com.adobe.acs.commons.util.impl.exception.CacheMBeanException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Node (javax.jcr.Node)1 Session (javax.jcr.Session)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 OpenDataException (javax.management.openmbean.OpenDataException)1