我有一个点火缓存版本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
解决了这个问题。但这是要走的路吗?