2011-10-20 17 views
2

我有一個我想要放在ehcache中的100個項目(字符串)的列表。我會讓它們在1小時後過期。之後,我想讀取數據庫並刷新緩存。如何使用ehcache重新加載數據?

我一直無法找到如何做到這一點的例子?

有人知道嗎?

感謝

回答

1

這裏是CacheConfiguration的方法來設置元素的生存時間緩存 http://ehcache.org/apidocs/net/sf/ehcache/config/CacheConfiguration.html#timeToLiveSeconds(long

它在高速緩存中 http://ehcache.org/apidocs/net/sf/ehcache/Cache.html#Cache%28java.lang.String,%20int,%20boolean,%20boolean,%20long,%20long%29

的構造函數的相應參數,這些都是默認particaluar緩存中元素的值 - 它也可以指定爲精確元素 http://ehcache.org/apidocs/net/sf/ehcache/Element.html#setTimeToLive(int

下面是一個使用它的小例子:

輸出幾乎都是1000,所以精度是相當不錯的。使用Ehcache 2.4.6

相關問題