ehcache - Ehcache中的缓存失效

标签 ehcache

我在 Hibernate 中使用 Ehcache。

如何通知缓存数据库已更改?如何使缓存数据失效?我怎样才能以编程方式实现这一点?

最佳答案

具体是什么意思?有两种方法可以在数据库中进行更改:应用程序内部和应用程序外部

在应用程序内,您可以轻松触发失效。第二个问题比较难解决。缓存元素使用键存储,并且根据该键您可以删除它。

CacheManager manager = CacheManager.getInstance();
cache = manager.getCache(cacheName);
cache.remove(key);

or 

cache.removeAll();

当然取决于你如何配置 ehcache。但您需要知道保存该对象的缓存的名称。

关于ehcache - Ehcache中的缓存失效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5830497/

相关文章:

java - hibernate 缓存 : Are objects returned by a cached query stored in L2 cache?

java - GAE 中的 Hibernate Ehcache 抛出 java.lang.NoClassDefFoundError : java. rmi.server.UID 是受限类

Java ehCache,如何替换成员

java - 如何检查 Ehcache 2.10.x 中的过期条目

java - org.hibernate.cache.CacheException : On-the-fly creation of JCache Cache objects is not supported in HIBERNATE

hibernate - Ehcache 存储但不检索(Ehcache + Hibernate)

java - Spring MVC 中的 ehcache

java - 指定全局EhCache容量

java - 如何以编程方式更改 EhCache 成员的到期时间

java - Ehcache 复制缓存 RMI Bootstrap