/** * * <b>创建缓存</b> * <p> * 创建缓存,若已存在直接返回。 * <p> * @param cacheName * @return Ehcache */ public static Ehcache createCache(String cacheName) { Ehcache ehCache; CacheManager cacheManager = SpringContextHolder.getBean(CacheManager.class); if (cacheManager.cacheExists(cacheName)) { if (logger.isDebugEnabled()) { logger.debug("Using existing EHCache cache region '" + cacheName + "'"); } ehCache = cacheManager.getEhcache(cacheName); } else { if (logger.isDebugEnabled()) { logger.debug("Creating new EHCache cache region '" + cacheName + "'"); } ehCache = createDefaultCache(cacheName); cacheManager.addCache(ehCache); } return ehCache; }