其他分享
首页 > 其他分享> > spring缓存创建

spring缓存创建

作者:互联网

    /**
     * 
     * <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;
    }

 

标签:ehCache,Ehcache,缓存,spring,cacheManager,cacheName,创建,logger
来源: https://www.cnblogs.com/zrboke/p/15314224.html