gpt4 book ai didi

java - 阻止 ignite 在调用 setter 时更新缓存

转载 作者:行者123 更新时间:2023-12-01 17:49:35 24 4
gpt4 key购买 nike

我有一个 ignite 缓存版本 2.2.0,配置如下:

final CacheConfiguration<String, Product> cacheConfiguration = new CacheConfiguration<>("products");

cacheConfiguration.setName("products");
cacheConfiguration.setIndexedTypes(String.class, Product.class);
cacheConfiguration.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
cacheConfiguration.setCacheStoreFactory(new FactoryBuilder.SingletonFactory<>( new ProductCacheStoreAdapter()));
cacheConfiguration.setCopyOnRead(false);
cacheConfiguration.setCacheMode(CacheMode.PARTITIONED);
cacheConfiguration.setOnheapCacheEnabled(true);

return cacheConfiguration;

该产品具有以下字段:

String id;
String brand;
ProductInfos infos;

当我现在从缓存中选择产品时:

log.info("product: ") + igniteCache.get("12345");

我得到以下信息:

product: 12345, beats, null

现在我执行以下操作:

product.setProductInfos(new ProductInfos(.......));
log.info("product: ") + igniteCache.get("12345");

我得到以下信息:

product: 12345, beats, {....}

这意味着通过在产品对象上设置产品信息,缓存会自动更新。

如何防止这种情况发生?

编辑

copyOnRead 设置为 true 可以修复此问题。但这是正确的方法吗?

最佳答案

由于启用堆上缓存和禁用 copyOnRead 的组合,您会获得此效果。

这意味着,当插入到缓存或从缓存中读取时,值存储在堆上而不是复制。仅当您不更改也存储在缓存中的值时,才应禁用 copyOnRead

关于java - 阻止 ignite 在调用 setter 时更新缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51877790/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com