我使用 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;
}
最初,当应用程序(Spring 应用程序)启动时,我将数据库中的所有数据加载到我的 ignite 缓存中。之后,我启动一个 Spring 调度程序任务,负责加载新数据并替换旧数据。通过替换,我并不是指替换当前缓存中存在的单个项目 - 我的意思是替换整个缓存 - 删除所有当前条目并添加所有新条目。
我遇到的问题是,在替换过程中,应用程序将无法使用,因为我首先必须删除所有数据,然后添加新数据。因此,没有可用数据的时间范围很短。我不想这样。
有没有办法在没有数据的时间范围内替换缓存?
最佳答案
考虑在 Ignite 中拥有两个缓存并在它们之间切换。
当定时任务被触发时,您可以创建一个新的缓存并开始向其中加载数据。读取进程仍然可以使用旧的缓存。加载完成后,您可以让读取进程切换到新的缓存,然后清理或销毁旧的缓存。
不过,您必须自己实现切换。例如,您可以使用复制的缓存来存储当前被视为 Activity 的缓存的名称。
关于java - 如何更换 ignite 缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51627291/