Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 点燃loadCache()并在后面写入_Java_Caching_Ignite_Data Persistence - Fatal编程技术网

Java 点燃loadCache()并在后面写入

Java 点燃loadCache()并在后面写入,java,caching,ignite,data-persistence,Java,Caching,Ignite,Data Persistence,我们使用的是Ignite,对于这个特定的缓存,当项目添加到缓存中时,我们希望使用write-behind在RDBMS中插入新行 问题是,我们希望首先用现有行加载缓存 目前,Ignite试图写入cache.loadCache()中加载的项,这显然不是所需的行为。我想以某种方式指出,这些项目不需要持久化 我的搜索没有找到任何有用的东西,如果可以,请告知。非常感谢 IgniteCache#loadCache应该忽略writeThrough,换句话说,通过loadCache方法加载的记录不应该插入到RD

我们使用的是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));
}
公共类CacheStoreExample{
公共静态void main(字符串[]args){
点火=点火。启动(
新配置()
.setCacheConfiguration(新缓存配置(“缓存”)
.setWriteThrough(true)
.setWriteBehindEnabled(真)
.setCacheStoreFactory(新工厂(){
@重写公共缓存存储创建(){
返回新的CacheStoreAdapter(){
@覆盖公共void加载缓存(IgniteBiInClosure clo、对象…args){
System.out.println(“使用单个键/值加载缓存:”);
clo.应用(1,1);
}
@重写公共对象加载(对象键)抛出CacheLoaderException{return null;}
@重写公共无效写入(Cache.Entry)引发CacheWriterException{
System.out.println(“写入条目:”+条目);
}
@重写公共void delete(对象键)引发CacheWriterException{}
};
}
})
));
IgniteCache=ignite.cache(“缓存”);
loadCache((k,v)->true);
System.out.println(“第一条记录:+cache.get(1));
System.out.println(“Put操作跳过存储”);
cache.withSkipStore().put(2,2);
System.out.println(“第二条记录:“+cache.get(2));
System.out.println(“带写入槽的Put操作”);
cache.put(3,3);
System.out.println(“第三条记录:+cache.get(3));
}

}

如何在loadCache方法中保存记录?您是否正在使用IgniteCache#put?您需要使用loadCache方法(IgniteBiInClosure)的第一个参数。谢谢,这很有帮助!