[英]Ignite loadCache() and write behind
我們正在使用 Ignite,對於這個特定的緩存,我們希望在將項目添加到緩存時使用 write behind 在 RDBMS 中插入新行。
問題是,我們希望最初使用現有行加載緩存。
目前,Ignite 嘗試寫入在 cache.loadCache() 中加載的項目,這顯然不是預期的行為。 我想以某種方式表明這些項目不需要持久化。
我的搜索沒有發現任何有用的東西,如果可以,請告知。 非常感謝!
IgniteCache#loadCache應該忽略 writeThrough,換句話說,通過loadCache方法加載的記錄不應該插入到 RDBMS。
第二個選項是使用通過 IgniteCache#witkSkipStore() 或 IgniteDataStreamer#skipStore 獲得的緩存/數據流實例手動加載數據。
public class CacheStoreExample {
public static void main(String[] args) {
Ignite ignite = Ignition.start(
new IgniteConfiguration()
.setCacheConfiguration(new CacheConfiguration("cache")
.setWriteThrough(true)
.setWriteBehindEnabled(true)
.setCacheStoreFactory(new Factory<CacheStore>() {
@Override public CacheStore create() {
return new CacheStoreAdapter() {
@Override public void loadCache(IgniteBiInClosure clo, Object... args) {
System.out.println("Loading cache with single a single key/value:");
clo.apply(1,1);
}
@Override public Object load(Object key) throws CacheLoaderException {return null; }
@Override public void write(Cache.Entry entry) throws CacheWriterException {
System.out.println("Writing entry: "+entry);
}
@Override public void delete(Object key) throws CacheWriterException {}
};
}
})
));
IgniteCache<Object, Object> cache = ignite.cache("cache");
cache.loadCache((k, v) -> true);
System.out.println("The first record:"+cache.get(1));
System.out.println("Put operation skipping store");
cache.withSkipStore().put(2,2);
System.out.println("The second records:"+cache.get(2));
System.out.println("Put operation with write trough");
cache.put(3,3);
System.out.println("The third record:"+cache.get(3));
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.