2011-02-09 55 views
2

我们正在使用由xml配置的web-ehcache的net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter来缓存JSON消息的页面,但此消息可以由管理员更改。管理员更改时如何使缓存失效更改JSON消息?如何使用Ehcache中的SimpleCachingPageFilter更新或无效缓存?

+0

同样的问题在这里http://forums.terracotta.org/forums/posts/list/4720.page – 2011-02-09 05:57:15

回答

3

我想通了,如何使它:

CacheManager.getInstance().getEhcache("CacheName").removeAll(); 

它得到singletone CacheManager中,然后得到了Ehcache取决于名字的缓存,然后删除元素。

在对该缓存页面的下一个请求中,筛选器查找Ehcache,但找不到elementx和UPDATES元素!

0

我通过设置生存时间为5分钟解决这个问题:

<cache name="SimplePageCachingFilter" 
    maxElementsInMemory="100" 
    eternal="false" 
    timeToIdleSeconds="300" 
    timeToLiveSeconds="300" 
    overflowToDisk="true" /> 
+0

感谢您的好主意,如果您有兴趣,我发布了另一个关于ehcache的问题http://stackoverflow.com/questions/4954683/using-ehcache-to-create-cachingfilter – 2011-02-10 08:05:27