Reputation: 10569
I have an ignite cache version 2.2.0 with the following configuration:
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;
The product has the following fields:
String id;
String brand;
ProductInfos infos;
When I now select a product from the cache:
log.info("product: ") + igniteCache.get("12345");
I get the following:
product: 12345, beats, null
Now I do the following:
product.setProductInfos(new ProductInfos(.......));
log.info("product: ") + igniteCache.get("12345");
And I get the following:
product: 12345, beats, {....}
So that means that by setting the product infos on the product object the cache automatically got updated.
How can I prevent that?
EDIT
setting copyOnRead
to be true
fixes this issue. but is that the way to go?
Upvotes: 0
Views: 174
Reputation: 3591
You get this effect because of a combination of enabled on-heap cache and disabled copyOnRead
.
It means, that values are stored on heap and not copied, when inserted to and read from the cache. copyOnRead
should be disabled only when you don't change values, that are also stored in cache.
Upvotes: 4