Search in sources :

Example 56 with CacheManager

use of net.sf.ehcache.CacheManager in project oc-explorer 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 57 with CacheManager

use of net.sf.ehcache.CacheManager in project hibernate-orm by hibernate.

the class EhcacheStatsImplTest method createCache.

@BeforeClass
public static void createCache() throws Exception {
    CacheManager manager = CacheManager.getInstance();
    stats = new EhcacheStatsImpl(manager);
}
Also used : EhcacheStatsImpl(org.hibernate.cache.ehcache.management.impl.EhcacheStatsImpl) CacheManager(net.sf.ehcache.CacheManager) BeforeClass(org.junit.BeforeClass)

Example 58 with CacheManager

use of net.sf.ehcache.CacheManager in project spring-framework by spring-projects.

the class EhCacheSupportTests method testEhCacheFactoryBeanWithBlockingCache.

@Test
public void testEhCacheFactoryBeanWithBlockingCache() throws Exception {
    EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
    cacheManagerFb.afterPropertiesSet();
    try {
        CacheManager cm = cacheManagerFb.getObject();
        EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
        cacheFb.setCacheManager(cm);
        cacheFb.setCacheName("myCache1");
        cacheFb.setBlocking(true);
        assertEquals(cacheFb.getObjectType(), BlockingCache.class);
        cacheFb.afterPropertiesSet();
        Ehcache myCache1 = cm.getEhcache("myCache1");
        assertTrue(myCache1 instanceof BlockingCache);
    } finally {
        cacheManagerFb.destroy();
    }
}
Also used : BlockingCache(net.sf.ehcache.constructs.blocking.BlockingCache) CacheManager(net.sf.ehcache.CacheManager) Ehcache(net.sf.ehcache.Ehcache) Test(org.junit.Test)

Example 59 with CacheManager

use of net.sf.ehcache.CacheManager in project spring-framework by spring-projects.

the class EhCacheSupportTests method testBlankCacheManager.

@Test
public void testBlankCacheManager() throws Exception {
    EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
    cacheManagerFb.setCacheManagerName("myCacheManager");
    assertEquals(CacheManager.class, cacheManagerFb.getObjectType());
    assertTrue("Singleton property", cacheManagerFb.isSingleton());
    cacheManagerFb.afterPropertiesSet();
    try {
        CacheManager cm = cacheManagerFb.getObject();
        assertTrue("Loaded CacheManager with no caches", cm.getCacheNames().length == 0);
        Cache myCache1 = cm.getCache("myCache1");
        assertTrue("No myCache1 defined", myCache1 == null);
    } finally {
        cacheManagerFb.destroy();
    }
}
Also used : CacheManager(net.sf.ehcache.CacheManager) SelfPopulatingCache(net.sf.ehcache.constructs.blocking.SelfPopulatingCache) BlockingCache(net.sf.ehcache.constructs.blocking.BlockingCache) UpdatingSelfPopulatingCache(net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache) Cache(net.sf.ehcache.Cache) Test(org.junit.Test)

Example 60 with CacheManager

use of net.sf.ehcache.CacheManager in project spring-framework by spring-projects.

the class EhCacheCacheTests method setUp.

@Before
public void setUp() {
    cacheManager = new CacheManager(new Configuration().name("EhCacheCacheTests").defaultCache(new CacheConfiguration("default", 100)));
    nativeCache = new net.sf.ehcache.Cache(new CacheConfiguration(CACHE_NAME, 100));
    cacheManager.addCache(nativeCache);
    cache = new EhCacheCache(nativeCache);
}
Also used : CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Before(org.junit.Before)

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