本文整理匯總了Java中net.sf.ehcache.CacheManager.getInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java CacheManager.getInstance方法的具體用法?Java CacheManager.getInstance怎麽用?Java CacheManager.getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.sf.ehcache.CacheManager
的用法示例。
在下文中一共展示了CacheManager.getInstance方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCache
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
/**
* 獲取緩存
* @param cacheName
* @return
*/
private static Cache getCache(String cacheName) {
CacheManager cacheManager = CacheManager.getInstance();
if (null == cacheManager) {
return null;
}
Cache cache = cacheManager.getCache(cacheName);
if (null == cache) {
return null;
}
return cache;
}
示例2: getRetentionCache
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
/**
* Returns reference to retention cache
*/
private RetentionCache getRetentionCache() throws CacheException {
final CacheManager manager = CacheManager.getInstance();
final Cache cache = manager.getCache("retention_cache");
if (cache == null) {
return DUMMY_STATELESS_RETENTION_CACHE;
} else {
return new DelegatingRetentionCache(cache);
}
}
示例3: resetAllCaches
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
public static void resetAllCaches() throws CacheException, IOException {
final CacheManager cacheManager = CacheManager.getInstance();
final String[] cacheNames = cacheManager.getCacheNames();
for (int i = 0; i < cacheNames.length; i++) {
final String cacheName = cacheNames[i];
if (cacheName.equals("retention_cache")) continue;
//if (log.isDebugEnabled()) log.debug("cache hits before setup: " + cacheName + "/" + cache.getHitCount());
cacheManager.getCache(cacheName).removeAll();
}
}
示例4: afterPropertiesSet
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
@Override
public void afterPropertiesSet() throws CacheException, IOException {
// If no cache name given, use bean name as cache name.
String cacheName = getName();
if (cacheName == null) {
cacheName = this.beanName;
setName(cacheName);
}
// If no CacheManager given, fetch the default.
if (this.cacheManager == null) {
if (logger.isDebugEnabled()) {
logger.debug("Using default EhCache CacheManager for cache region '" + cacheName + "'");
}
this.cacheManager = CacheManager.getInstance();
}
synchronized (this.cacheManager) {
// Fetch cache region: If none with the given name exists, create one on the fly.
Ehcache rawCache;
boolean cacheExists = this.cacheManager.cacheExists(cacheName);
if (cacheExists) {
if (logger.isDebugEnabled()) {
logger.debug("Using existing EhCache cache region '" + cacheName + "'");
}
rawCache = this.cacheManager.getEhcache(cacheName);
}
else {
if (logger.isDebugEnabled()) {
logger.debug("Creating new EhCache cache region '" + cacheName + "'");
}
rawCache = createCache();
rawCache.setBootstrapCacheLoader(this.bootstrapCacheLoader);
}
if (this.cacheEventListeners != null) {
for (CacheEventListener listener : this.cacheEventListeners) {
rawCache.getCacheEventNotificationService().registerListener(listener);
}
}
// Needs to happen after listener registration but before setStatisticsEnabled
if (!cacheExists) {
this.cacheManager.addCache(rawCache);
}
// Only necessary on EhCache <2.7: As of 2.7, statistics are on by default.
if (setStatisticsAvailable) {
if (this.statisticsEnabled) {
rawCache.setStatisticsEnabled(true);
}
if (this.sampledStatisticsEnabled) {
rawCache.setSampledStatisticsEnabled(true);
}
}
if (this.disabled) {
rawCache.setDisabled(true);
}
Ehcache decoratedCache = decorateCache(rawCache);
if (decoratedCache != rawCache) {
this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
}
this.cache = decoratedCache;
}
}
示例5: RealCache
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
public RealCache() {
super();
CacheManager manager = null;
synchronized (RealCache.class) {
manager = CacheManager.getInstance();
if (!manager.cacheExists("AFPDataGrabberCache")) {
Cache cache = new Cache(new CacheConfiguration("AFPDataGrabberCache", 50000).memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
.eternal(true).timeToLiveSeconds(0).timeToIdleSeconds(0).persistence(new PersistenceConfiguration().strategy(Strategy.NONE)));
manager.addCache(cache);
}
}
ehcache = manager.getCache("AFPDataGrabberCache");
}
示例6: makeCacheStatsPanel
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
/**
* Creates cache stats panel.
*/
private Panel makeCacheStatsPanel() {
final MessagePanel result = new MessagePanel("Cache statistis");
try {
final GridIterator gi = new GridIterator(result.getUserPanel(), 5);
gi.add(new BoldCommonLabel("Name"))
.add(new BoldCommonLabel("Hit count"))
.add(new BoldCommonLabel("Miss count expired"))
.add(new BoldCommonLabel("Miss count not found"))
.add(new BoldCommonLabel("Miss percent"))
;
final CacheManager cacheMan = CacheManager.getInstance();
final String[] cacheNames = cacheMan.getCacheNames();
Arrays.sort(cacheNames);
int totalHitCount = 0;
int totalMissCount = 0;
for (int i = 0; i < cacheNames.length; i++) {
// get cache
final String cacheName = cacheNames[i];
final Cache cache = cacheMan.getCache(cacheName);
final int hitCount = cache.getHitCount();
final int missCountExpired = cache.getMissCountExpired();
final int missCountNotFound = cache.getMissCountNotFound();
final int missCount = missCountExpired + missCountNotFound;
final int accessCount = missCount + hitCount;
final int missPercent = accessCount == 0 ? 0 : (missCount * 100) / accessCount;
totalHitCount += hitCount;
totalMissCount += missCount;
// add attrs
gi.add(new AboutLabel(cacheName));
gi.add(new AboutLabel(Integer.toString(hitCount)));
gi.add(new AboutLabel(Integer.toString(missCountExpired)));
gi.add(new AboutLabel(Integer.toString(missCountNotFound)));
final CommonLabel lbMissPercent = new AboutLabel(Integer.toString(missPercent));
lbMissPercent.setAlignX(Layout.RIGHT);
gi.add(lbMissPercent);
}
// add total
final int totalAccessCount = totalHitCount + totalMissCount;
final int totalMissPercent = totalAccessCount == 0 ? 0 : (totalMissCount * 100) / totalAccessCount;
gi.add(new CommonLabel("--- Total -- "));
gi.add(new CommonLabel(""));
gi.add(new CommonLabel(""));
gi.add(new CommonLabel(""));
gi.add(new CommonLabel(Integer.toString(totalMissPercent)));
} catch (CacheException e) {
result.showErrorMessage("Error getting cache stats: " + e.toString());
}
return result;
}