Reputation: 31
I have done some test using setStoreByValue(true/false) and I do not appreciate the difference.
I expect to store in the cache a lot of more that 30 objects when I use store by reference.
CacheManager manager = Caching.getCachingProvider().getCacheManager();
MutableConfiguration<String, CaLpgDataCollectionDto<CaBigNumber>> configuration = new MutableConfiguration<String, CaLpgDataCollectionDto<CaBigNumber>>();
configuration.setStoreByValue(false);
Cache<String, CaLpgDataCollectionDto<CaBigNumber>> testCache = manager.createCache("testCache", configuration);
//ICache is a Hazelcast interface that extends JCache, provides more functionality
ICache<String, CaLpgDataCollectionDto<CaBigNumber>> icache = testCache.unwrap(ICache.class);
List<CaLpgDataRowDto<CaBigNumber>> bigList = lpgDatasource.getDataRows();
while (bigList.size() <= 5000000)
{
bigList.addAll(bigList);
}
lpgDatasource.setDataRows(bigList);
System.out.println("Free memory before (bytes): " + Runtime.getRuntime().freeMemory());
for (int i = 0; i < 30 ; i++)
{
icache.put("objectTest"+i, lpgDatasource);
}
Am I using properly this propertie?
Kind regards.
Upvotes: 0
Views: 64
Reputation: 823
JSR107 standard specifies that store-by-reference is an optional feature (see page 9 of JSR107 1.1.1 specification here. You can query a CachingProvider
to test whether an optional feature is supported via CachingProvider#isSupported(OptionalFeature)
.
Hazelcast, being primarily used as a distributed cache, does not support store by reference. Keys and values have to be serializable in order to be transferred across the network among Hazelcast members and clients. Also, depending on the chosen in-memory storage format, values can be stored as serialized blobs (the default option with BINARY
in-memory format) or as deserialized objects, however even in the latter case the value is serialized/deserialized first so it is a clone of the original.
Upvotes: 1