Search in sources :

Example 1 with CacheContent

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

the class HttpCacheEngineImpl method deliverCacheContent.

@Override
public boolean deliverCacheContent(SlingHttpServletRequest request, SlingHttpServletResponse response, HttpCacheConfig cacheConfig) throws HttpCacheKeyCreationException, HttpCacheDataStreamException, HttpCachePersistenceException {
    // Get the cached content from cache
    CacheContent cacheContent = getCacheStore(cacheConfig).getIfPresent(cacheConfig.buildCacheKey(request));
    if (!isRequestDeliverableFromCacheAccordingToHandlingRules(request, response, cacheConfig, cacheContent)) {
        return false;
    }
    prepareCachedResponse(response, cacheContent);
    return executeCacheContentDeliver(request, response, cacheContent);
}
Also used : CacheContent(com.adobe.acs.commons.httpcache.engine.CacheContent)

Example 2 with CacheContent

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

the class EntryNodeMapVisitorTest method testNoEntries.

@Test
public void testNoEntries() throws Exception {
    final RootNodeMockFactory.Settings settings = new RootNodeMockFactory.Settings();
    settings.setEntryNodeCount(0);
    final Node rootNode = new RootNodeMockFactory(settings).build();
    final EntryNodeMapVisitor visitor = getMockedNodeMapVisitor();
    visitor.visit(rootNode);
    final Map<CacheKey, CacheContent> cache = visitor.getCache();
    assertTrue(cache.isEmpty());
}
Also used : RootNodeMockFactory(com.adobe.acs.commons.httpcache.store.jcr.impl.visitor.mock.RootNodeMockFactory) Node(javax.jcr.Node) CacheContent(com.adobe.acs.commons.httpcache.engine.CacheContent) CacheKey(com.adobe.acs.commons.httpcache.keys.CacheKey) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with CacheContent

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

the class EntryNodeMapVisitorTest method test5BucketDepth.

@Test
public void test5BucketDepth() throws Exception {
    final RootNodeMockFactory.Settings settings = new RootNodeMockFactory.Settings();
    settings.setEntryNodeCount(10);
    settings.setBucketDepth(5);
    final Node rootNode = new RootNodeMockFactory(settings).build();
    final EntryNodeMapVisitor visitor = getMockedNodeMapVisitor();
    visitor.visit(rootNode);
    final Map<CacheKey, CacheContent> cache = visitor.getCache();
    assertEquals(10, cache.size());
}
Also used : RootNodeMockFactory(com.adobe.acs.commons.httpcache.store.jcr.impl.visitor.mock.RootNodeMockFactory) Node(javax.jcr.Node) CacheContent(com.adobe.acs.commons.httpcache.engine.CacheContent) CacheKey(com.adobe.acs.commons.httpcache.keys.CacheKey) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with CacheContent

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

the class MemHttpCacheStoreImpl method getIfPresent.

@Override
public CacheContent getIfPresent(CacheKey key) {
    MemCachePersistenceObject value = cache.getIfPresent(key);
    if (null == value) {
        return null;
    }
    // Increment hit count
    value.incrementHitCount();
    return new CacheContent(value.getStatus(), value.getCharEncoding(), value.getContentType(), value.getHeaders(), new ByteArrayInputStream(value.getBytes()));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CacheContent(com.adobe.acs.commons.httpcache.engine.CacheContent)

Example 5 with CacheContent

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

the class EntryNodeWriterMocks method mockCacheContent.

private void mockCacheContent() {
    cacheContent = mock(CacheContent.class);
    when(cacheContent.getCharEncoding()).thenReturn(arguments.cacheContentCharEncoding);
    when(cacheContent.getContentType()).thenReturn(arguments.cacheContentType);
    when(cacheContent.getInputDataStream()).thenReturn(arguments.cacheContent);
    when(cacheContent.getStatus()).thenReturn(arguments.status);
    when(cacheContent.getHeaders()).thenReturn(arguments.cacheContentHeaders);
    when(cacheContent.getTempSink()).thenReturn(new MemTempSinkImpl());
}
Also used : MemTempSinkImpl(com.adobe.acs.commons.httpcache.store.mem.impl.MemTempSinkImpl) CacheContent(com.adobe.acs.commons.httpcache.engine.CacheContent)

Aggregations

CacheContent (com.adobe.acs.commons.httpcache.engine.CacheContent)10 CacheKey (com.adobe.acs.commons.httpcache.keys.CacheKey)6 Node (javax.jcr.Node)5 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 IOException (java.io.IOException)2 HttpCacheServletResponseWrapper (com.adobe.acs.commons.httpcache.engine.HttpCacheServletResponseWrapper)1 HttpCacheDataStreamException (com.adobe.acs.commons.httpcache.exception.HttpCacheDataStreamException)1 BucketNodeHandler (com.adobe.acs.commons.httpcache.store.jcr.impl.handler.BucketNodeHandler)1 EntryNodeToCacheContentHandler (com.adobe.acs.commons.httpcache.store.jcr.impl.handler.EntryNodeToCacheContentHandler)1 BucketNodeFactory (com.adobe.acs.commons.httpcache.store.jcr.impl.writer.BucketNodeFactory)1 MemTempSinkImpl (com.adobe.acs.commons.httpcache.store.mem.impl.MemTempSinkImpl)1 CacheMBeanException (com.adobe.acs.commons.util.impl.exception.CacheMBeanException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 OpenDataException (javax.management.openmbean.OpenDataException)1