Search in sources :

Example 21 with CacheManager

use of net.sf.ehcache.CacheManager in project Mycat_plus by coderczp.

the class EnchachePooFactory method createCachePool.

@Override
public CachePool createCachePool(String poolName, int cacheSize, int expiredSeconds) {
    CacheManager cacheManager = CacheManager.create();
    Cache enCache = cacheManager.getCache(poolName);
    if (enCache == null) {
        CacheConfiguration cacheConf = cacheManager.getConfiguration().getDefaultCacheConfiguration().clone();
        cacheConf.setName(poolName);
        if (cacheConf.getMaxEntriesLocalHeap() != 0) {
            cacheConf.setMaxEntriesLocalHeap(cacheSize);
        } else {
            cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize));
        }
        cacheConf.setTimeToIdleSeconds(expiredSeconds);
        Cache cache = new Cache(cacheConf);
        cacheManager.addCache(cache);
        return new EnchachePool(poolName, cache, cacheSize);
    } else {
        return new EnchachePool(poolName, enCache, cacheSize);
    }
}
Also used : CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache)

Example 22 with CacheManager

use of net.sf.ehcache.CacheManager in project vip by guangdada.

the class EhcacheFactory method getOrAddCache.

static Cache getOrAddCache(String cacheName) {
    CacheManager cacheManager = getCacheManager();
    Cache cache = cacheManager.getCache(cacheName);
    if (cache == null) {
        synchronized (locker) {
            cache = cacheManager.getCache(cacheName);
            if (cache == null) {
                log.warn("无法找到缓存 [" + cacheName + "]的配置, 使用默认配置.");
                cacheManager.addCacheIfAbsent(cacheName);
                cache = cacheManager.getCache(cacheName);
                log.debug("缓存 [" + cacheName + "] 启动.");
            }
        }
    }
    return cache;
}
Also used : CacheManager(net.sf.ehcache.CacheManager) Cache(net.sf.ehcache.Cache)

Example 23 with CacheManager

use of net.sf.ehcache.CacheManager in project ocvn 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();
    }
}
Also used : CacheManager(net.sf.ehcache.CacheManager) MarkupCache(org.apache.wicket.markup.MarkupCache) Cache(net.sf.ehcache.Cache)

Example 24 with CacheManager

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

the class MarkupCacheService method getReportsStat.

/**
 * Display some statistics about reports cache
 */
public void getReportsStat() {
    CacheManager cm = CacheManager.getInstance();
    // get the reports cache "reportsCache", declared in ehcache.xml
    Cache cache = cm.getCache("reportsCache");
    @SuppressWarnings("unchecked") List<String> cacheKeys = cache.getKeys();
    long size = 0;
    for (String k : cacheKeys) {
        logger.info("key: " + k);
        byte[] buf = (byte[]) cache.get(k).getObjectValue();
        size += buf.length;
    }
    Statistics stats = cache.getStatistics();
    StringBuffer sb = new StringBuffer();
    sb.append(String.format("%s objects, %s hits, %s misses\n", stats.getObjectCount(), stats.getCacheHits(), stats.getCacheMisses()));
    logger.info(String.valueOf(sb));
    logger.info("cache total size: " + FileUtils.byteCountToDisplaySize(size));
}
Also used : CacheManager(net.sf.ehcache.CacheManager) Statistics(net.sf.ehcache.Statistics) MarkupCache(org.apache.wicket.markup.MarkupCache) Cache(net.sf.ehcache.Cache)

Example 25 with CacheManager

use of net.sf.ehcache.CacheManager in project joynr by bmwcarit.

the class ClusteredBounceProxyControllerTest method waitForCachesJoiningCluster.

private void waitForCachesJoiningCluster() throws InterruptedException {
    CacheManager cacheManager = CacheManager.newInstance(getClass().getResource("/ehcache_distributed_test.xml"));
    CacheManagerPeerProvider peerProvider = cacheManager.getCacheManagerPeerProvider("RMI");
    int peers = 0;
    long timeoutMs = 10000;
    long startMs = System.currentTimeMillis();
    do {
        Thread.sleep(1000);
        peers = peerProvider.listRemoteCachePeers(cacheManager.getEhcache("bpCache1")).size();
    } while (peers < 2 && (System.currentTimeMillis() - startMs < timeoutMs));
    Assert.assertEquals(2, peers);
    cacheManager.shutdown();
}
Also used : CacheManager(net.sf.ehcache.CacheManager) CacheManagerPeerProvider(net.sf.ehcache.distribution.CacheManagerPeerProvider)

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