如何在没有服务器重启的情况下清除ehcache
虽然我猜它极不可能 – 但有没有办法在不重新启动服务器的情况下清除ehcache? 我需要清除缓存以进行一些测试 – 我无法更改代码,也无法多次重启服务器。
PS:我正在使用apache-tomcat-5.5.25请让我知道。 谢谢,psvm
你通过JMX公开Ehcache吗? 然后,您可以使用Jvisualvm等工具使用JMX操作清除缓存。 查找net.sf.ehcache.CacheManager
等net.sf.ehcache.CacheManager
,它提供clearAll()
操作。
使用spring + hibernate并暴露mbean:
import org.hibernate.Cache; import org.hibernate.SessionFactory; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import javax.annotation.Resource; @Component("CacheManagerMBean") public class CacheManagerMBean { private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CacheManagerMBean.class); @Resource(name = "sessionFactory") private SessionFactory sessionFactory; public void clearCache() { Cache cache = sessionFactory.getCache(); if (null != cache) { logger.info("Clearing cache..."); cache.evictAll(); cache.evictAllRegions(); logger.info("Clearing cache...Done!"); } else { logger.error("No second level cache available for session-factory"); } } }
XML配置:
然后使用jconsole连接到java进程并使用Mbean方法调用 – 清除二级缓存!
- java.lang.NoClassDefFoundError:org / hibernate / cache / EntityRegion配置EHCache
- Spring:hibernate + ehcache
- EhCache在java中默认缓存
- Spring Boot,使用EhCache进行缓存
- 如何在不使用查询缓存的情况下缓存Spring Data JPA查询方法的结果?
- Ehcache – 在数据不存在时使用SelfPopulatingCache
- 引起:java.lang.NoClassDefFoundError:当tomcat / lib下存在类时?
- 多级进程内缓存的更好选择是什么?
- 可以同时安全地访问ehcache diskstore吗?