hazelcast/hazelcast — pull request #2350 by lukasblu (2014-04-25 13:51:10+00:00)
Title: Return cached value upon IMap.get() if near cache is enabled

Hi,

currently, if a local near cache with in-memory format OBJECT is enabled, calling IMap.get() deserializes a map entry value twice: Once when putting the value into the near cache and once when returning the fetched value to the caller. If deserialization is expensive, this is quite bad.

This pull request fixes that.

However, as a (possibly nice) side-effect, it also changes the object instances that are returned for the first call to get() and any following calls to get() which make use of the near cache.

Before this change, the returned instances could be described like this:
1. call of get(): returned object instance = 1 (this is the instance which is fetched from the map)
2. call of get(): returned object instance = 2 (this is the instance which resides in the near cache)
3. call of get(): returned object instance = 2 (this is the instance which resides in the near cache)
...

With this pull request applied, the sequence would look like this:
1. call of get(): returned object instance = 2 (this is the instance which resides in the near cache)
2. call of get(): returned object instance = 2 (this is the instance which resides in the near cache)
3. call of get(): returned object instance = 2 (this is the instance which resides in the near cache)
...

I think the second sequence is better for developers, because the returned instance does not change.

What do you think of this pull request?

Thanks and best,
Lukas