Java 如何更换ignite缓存?

Java 如何更换ignite缓存?,java,spring,caching,configuration,ignite,Java,Spring,Caching,Configuration,Ignite,Im使用ignite版本2.2.0,我有以下缓存配置: private CacheConfiguration<String, Product> getProductCacheConfiguration() { final CacheConfiguration<String, Product> cacheConfiguration = new CacheConfiguration<>(Identifiers.PRODUCT_IGNITE_CACHE);

Im使用ignite版本
2.2.0
,我有以下缓存配置:

private CacheConfiguration<String, Product> getProductCacheConfiguration() {
    final CacheConfiguration<String, Product> cacheConfiguration = new CacheConfiguration<>(Identifiers.PRODUCT_IGNITE_CACHE);

    cacheConfiguration.setName(Identifiers.PRODUCT_IGNITE_CACHE);
    cacheConfiguration.setIndexedTypes(String.class, Product.class);
    cacheConfiguration.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    cacheConfiguration.setCacheStoreFactory(new FactoryBuilder.SingletonFactory<>(new ProductCacheStoreAdapter(this.databaseConfiguration)));
    cacheConfiguration.setReadThrough(true);
    cacheConfiguration.setWriteThrough(true);
    cacheConfiguration.setCopyOnRead(false);
    cacheConfiguration.setCacheMode(CacheMode.PARTITIONED);
    cacheConfiguration.setOnheapCacheEnabled(true);

    return cacheConfiguration;
}
private CacheConfiguration getProductCacheConfiguration(){
final CacheConfiguration CacheConfiguration=新的CacheConfiguration(Identifiers.PRODUCT\u IGNITE\u CACHE);
cacheConfiguration.setName(标识符.PRODUCT\u IGNITE\u缓存);
cacheConfiguration.setIndexedTypes(String.class、Product.class);
setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
setCacheStoreFactory(新的FactoryBuilder.SingletonFactory(新的ProductCacheStoreAdapter(this.databaseConfiguration));
cacheConfiguration.setReadThrough(true);
cacheConfiguration.setWriteThrough(true);
cacheConfiguration.setCopyOnRead(false);
cacheConfiguration.setCacheMode(CacheMode.PARTITIONED);
cacheConfiguration.setOnheapCacheEnabled(true);
返回缓存配置;
}
最初,当应用程序(spring应用程序)启动时,我将数据库中的所有数据加载到ignite缓存中。之后,我启动一个spring调度程序任务,该任务负责加载新数据并替换旧数据。通过替换,我的意思不是替换当前缓存中存在的单个项-我的意思是替换整个缓存-删除所有当前项并添加所有新项

我在这里遇到的问题是,在这个替换过程中,应用程序将不可用,因为我首先必须删除所有数据,然后添加新数据。因此,在没有可用数据的情况下,时间很短。我不想那样


有没有一种方法可以在没有数据的时间范围内替换缓存?

考虑在Ignite中有两个缓存并在它们之间切换

触发计划任务后,可以创建新缓存并开始向其中加载数据。读取进程仍然可以使用旧缓存。加载完成后,您可以让读取进程切换到新缓存,然后-清除或销毁旧缓存


不过,您必须自己实现切换。例如,您可以使用复制缓存来存储当前被视为活动的缓存的名称。

考虑在Ignite中有两个缓存并在它们之间切换

触发计划任务后,可以创建新缓存并开始向其中加载数据。读取进程仍然可以使用旧缓存。加载完成后,您可以让读取进程切换到新缓存,然后-清除或销毁旧缓存


不过,您必须自己实现切换。例如,您可以使用复制缓存来存储当前被视为活动的缓存的名称。

Oh yes。我可以这样做。我将为缓存提供动态标识符。有时间戳的美宝莲。谢谢你的提示。哦,是的。我可以这样做。我将为缓存提供动态标识符。有时间戳的美宝莲。谢谢你的提示。