我使用cache2k作爲我的java應用程序的緩存。cache2k cachesource使用mysql作爲後端
如果緩存不在in-mermoy緩存中,我使用CacheSource進行get和peek請求。 但現在我想實施把的方法。
- 如何限制內存高速緩存爲例如1000個項目(可選:有時間)?
- 我怎樣才能把一個項目到內存和mysql?只需添加一個put方法到cachesource? (MySQL是永久緩存)
希望有人能幫助我。
private static Cache<String, Integer> c =
CacheBuilder.newCache(String.class, Integer.class)
.source(new CacheSource<String, Integer>() {
public Integer get(String o) {
System.out.println("ACCESSING SOURCE");
return checkCache(o) ? 1: 0; // checkCache checks if the item is in MySQL Cache
}
})
.name("cache")
.build();