/** * A bean for obtain initialize EhCacheManagerFactoryBean object * * @return a EhCacheManagerFactoryBean object */ @Bean @ProdProfile public EhCacheManagerFactoryBean ehCacheCacheManager() { EhCacheManagerFactoryBean cache = new EhCacheManagerFactoryBean(); cache.setConfigLocation(new ClassPathResource("cache/ehcache.xml")); cache.setShared(true); return cache; }
/** * 清除缓存 * * @param cacheName * @return */ public boolean clearCache(String cacheName) { CacheManager cacheManagerObject = cacheManager.getObject(); Cache cache = cacheManagerObject.getCache(cacheName); if (cache != null) { cache.removeAll(); return Boolean.TRUE; } else { return Boolean.FALSE; } }
@Bean public EhCacheManagerFactoryBean ehCacheManagerFactoryBean() { EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean(); ehCacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml")); return ehCacheManagerFactoryBean; }