当前位置: 首页>>代码示例>>Java>>正文


Java CacheManager.getInstance方法代码示例

本文整理汇总了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;
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:17,代码来源:EhCacheUtil.java

示例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);
  }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:13,代码来源:ErrorManagerImpl.java

示例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();
  }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:11,代码来源:CacheUtils.java

示例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;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:68,代码来源:EhCacheFactoryBean.java

示例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");
}
 
开发者ID:ina-foss,项目名称:afp-api-client,代码行数:14,代码来源:AFPDataGrabberCache.java

示例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;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:53,代码来源:AboutPage.java


注:本文中的net.sf.ehcache.CacheManager.getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。