Search in sources :

Example 1 with BucketNodeHandler

use of com.adobe.acs.commons.httpcache.store.jcr.impl.handler.BucketNodeHandler in project acs-aem-commons by Adobe-Consulting-Services.

the class JCRHttpCacheStoreImpl method getIfPresent.

@Override
public CacheContent getIfPresent(final CacheKey key) {
    final long currentTime = System.currentTimeMillis();
    incrementRequestCount();
    return withSession(new Function<Session, CacheContent>() {

        @Override
        public CacheContent apply(Session session) throws Exception {
            final BucketNodeFactory factory = new BucketNodeFactory(session, cacheRootPath, key, bucketTreeDepth);
            final Node bucketNode = factory.getBucketNode();
            if (bucketNode != null) {
                final Node entryNode = new BucketNodeHandler(bucketNode, dclm).getEntryIfExists(key);
                final CacheContent content = new EntryNodeToCacheContentHandler(entryNode).get();
                if (content != null) {
                    incrementTotalLookupTime(System.currentTimeMillis() - currentTime);
                    incrementHitCount();
                    return content;
                }
            }
            incrementTotalLookupTime(System.currentTimeMillis() - currentTime);
            incrementMissCount();
            return null;
        }
    });
}
Also used : BucketNodeFactory(com.adobe.acs.commons.httpcache.store.jcr.impl.writer.BucketNodeFactory) CacheContent(com.adobe.acs.commons.httpcache.engine.CacheContent) Node(javax.jcr.Node) EntryNodeToCacheContentHandler(com.adobe.acs.commons.httpcache.store.jcr.impl.handler.EntryNodeToCacheContentHandler) 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)

Example 2 with BucketNodeHandler

use of com.adobe.acs.commons.httpcache.store.jcr.impl.handler.BucketNodeHandler 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 3 with BucketNodeHandler

use of com.adobe.acs.commons.httpcache.store.jcr.impl.handler.BucketNodeHandler in project acs-aem-commons by Adobe-Consulting-Services.

the class JCRHttpCacheStoreImpl method contains.

@Override
public boolean contains(final CacheKey key) {
    final long currentTime = System.currentTimeMillis();
    incrementRequestCount();
    return withSession(new Function<Session, Boolean>() {

        @Override
        public Boolean apply(Session session) throws Exception {
            final BucketNodeFactory factory = new BucketNodeFactory(session, cacheRootPath, key, bucketTreeDepth);
            final Node bucketNode = factory.getBucketNode();
            if (bucketNode != null) {
                Node entryNode = new BucketNodeHandler(bucketNode, dclm).getEntryIfExists(key);
                if (entryNode != null) {
                    incrementTotalLookupTime(System.currentTimeMillis() - currentTime);
                    incrementHitCount();
                    return true;
                }
            }
            incrementTotalLookupTime(System.currentTimeMillis() - currentTime);
            incrementMissCount();
            return false;
        }
    });
}
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)

Aggregations

HttpCacheDataStreamException (com.adobe.acs.commons.httpcache.exception.HttpCacheDataStreamException)3 BucketNodeHandler (com.adobe.acs.commons.httpcache.store.jcr.impl.handler.BucketNodeHandler)3 BucketNodeFactory (com.adobe.acs.commons.httpcache.store.jcr.impl.writer.BucketNodeFactory)3 CacheMBeanException (com.adobe.acs.commons.util.impl.exception.CacheMBeanException)3 IOException (java.io.IOException)3 Node (javax.jcr.Node)3 Session (javax.jcr.Session)3 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)3 OpenDataException (javax.management.openmbean.OpenDataException)3 CacheContent (com.adobe.acs.commons.httpcache.engine.CacheContent)1 EntryNodeToCacheContentHandler (com.adobe.acs.commons.httpcache.store.jcr.impl.handler.EntryNodeToCacheContentHandler)1 EntryNodeWriter (com.adobe.acs.commons.httpcache.store.jcr.impl.writer.EntryNodeWriter)1