Search in sources :

Example 86 with CacheManager

use of net.sf.ehcache.CacheManager in project ocvn by devgateway.

the class MarkupCacheService method getReportFromCache.

/**
 * Fetch the content of a report from cache
 *
 * @param outputType
 * @param reportName
 * @param parameters
 * @return
 */
public byte[] getReportFromCache(final String outputType, final String reportName, final String parameters) {
    CacheManager cm = CacheManager.getInstance();
    // get the reports cache "reportsCache", declared in ehcache.xml
    Cache cache = cm.getCache("reportsCache");
    String key = createCacheKey(outputType, reportName, parameters);
    if (cache.isKeyInCache(key)) {
        return (byte[]) cache.get(key).getObjectValue();
    }
    return null;
}
Also used : CacheManager(net.sf.ehcache.CacheManager) MarkupCache(org.apache.wicket.markup.MarkupCache) Cache(net.sf.ehcache.Cache)

Example 87 with CacheManager

use of net.sf.ehcache.CacheManager in project ocvn by devgateway.

the class MarkupCacheService method addReportToCache.

/**
 * Add the content of a report (PDF, Excel, RTF) to cache
 *
 * @param outputType
 * @param reportName
 * @param parameters
 * @param buffer
 */
public void addReportToCache(final String outputType, final String reportName, final String parameters, final byte[] buffer) {
    CacheManager cm = CacheManager.getInstance();
    // get the reports cache "reportsCache", declared in ehcache.xml
    Cache cache = cm.getCache("reportsCache");
    cache.put(new Element(createCacheKey(outputType, reportName, parameters), buffer));
}
Also used : Element(net.sf.ehcache.Element) CacheManager(net.sf.ehcache.CacheManager) MarkupCache(org.apache.wicket.markup.MarkupCache) Cache(net.sf.ehcache.Cache)

Example 88 with CacheManager

use of net.sf.ehcache.CacheManager in project ocvn by devgateway.

the class MarkupCacheService method clearReportsCache.

/**
 * Remove from cache all reports content
 */
public void clearReportsCache() {
    CacheManager cm = CacheManager.getInstance();
    // get the reports cache "reportsCache", declared in ehcache.xml
    Cache cache = cm.getCache("reportsCache");
    if (cache != null) {
        cache.removeAll();
    }
}
Also used : CacheManager(net.sf.ehcache.CacheManager) MarkupCache(org.apache.wicket.markup.MarkupCache) Cache(net.sf.ehcache.Cache)

Example 89 with CacheManager

use of net.sf.ehcache.CacheManager in project uPortal by Jasig.

the class GroupsCacheAuthenticationListenerTest method testUserAuthenticated.

@Test
public void testUserAuthenticated() {
    final IPerson person = PersonFactory.createPerson();
    person.setAttribute(IPerson.USERNAME, "mock.person");
    final IEntityGroup group = new MockEntityGroup("mock.group", IPerson.class);
    final CacheManager cacheManager = CacheManager.getInstance();
    final Cache parentGroupsCache = new Cache("parentGroupsCache", 100, false, false, 0, 0);
    cacheManager.addCache(parentGroupsCache);
    parentGroupsCache.put(new Element(person.getEntityIdentifier(), Collections.singleton(group)));
    final Cache childrenCache = new Cache("childrenCache", 100, false, false, 0, 0);
    cacheManager.addCache(childrenCache);
    childrenCache.put(new Element(group.getUnderlyingEntityIdentifier(), new Object()));
    Assert.assertEquals(parentGroupsCache.getSize(), 1);
    Assert.assertEquals(childrenCache.getSize(), 1);
    final LocalGroupsCacheAuthenticationListener listener = new LocalGroupsCacheAuthenticationListener();
    listener.setParentGroupsCache(parentGroupsCache);
    listener.setChildrenCache(childrenCache);
    listener.userAuthenticated(person);
    Assert.assertEquals(parentGroupsCache.getSize(), 0);
    Assert.assertEquals(childrenCache.getSize(), 0);
}
Also used : IPerson(org.apereo.portal.security.IPerson) Element(net.sf.ehcache.Element) CacheManager(net.sf.ehcache.CacheManager) Cache(net.sf.ehcache.Cache) Test(org.junit.Test)

Example 90 with CacheManager

use of net.sf.ehcache.CacheManager in project oc-explorer by devgateway.

the class MarkupCacheService method clearReportsApiCache.

/**
 * Remove from cache all reports api content
 */
public void clearReportsApiCache() {
    CacheManager cm = CacheManager.getInstance();
    // get the reports cache "reportsApiCache", declared in ehcache.xml
    Cache cache = cm.getCache("reportsApiCache");
    if (cache != null) {
        cache.removeAll();
    }
    // get the reports cache "excelExportCache", declared in ehcache.xml
    Cache excelExportCache = cm.getCache("excelExportCache");
    if (excelExportCache != null) {
        excelExportCache.removeAll();
    }
}
Also used : CacheManager(net.sf.ehcache.CacheManager) MarkupCache(org.apache.wicket.markup.MarkupCache) Cache(net.sf.ehcache.Cache)

Aggregations

CacheManager (net.sf.ehcache.CacheManager)102 Cache (net.sf.ehcache.Cache)55 ClassPathResource (org.springframework.core.io.ClassPathResource)21 Element (net.sf.ehcache.Element)20 Configuration (net.sf.ehcache.config.Configuration)18 Test (org.junit.Test)18 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)17 MarkupCache (org.apache.wicket.markup.MarkupCache)10 CacheException (net.sf.ehcache.CacheException)9 IOException (java.io.IOException)7 Ehcache (net.sf.ehcache.Ehcache)7 UpdatingSelfPopulatingCache (net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache)6 URL (java.net.URL)5 BlockingCache (net.sf.ehcache.constructs.blocking.BlockingCache)5 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)5 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)4 PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)4 Around (org.aspectj.lang.annotation.Around)4 Before (org.junit.Before)4 File (java.io.File)3