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);
}
}
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;
}
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();
}
}
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));
}
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();
}
Aggregations