0

I'm using Spring @Cacheable annotation with Hazelcast 2.1 and Spring 3.1.

@Cacheable("testCache")
public MyObject testMethod(int testParam);

//After method call
MyObject test = Hazelcast.getMap("testCache").get("key")
test.setSomeProp()   //This line causes an update to the cache since it is reference.

Is it possible to return a clone/copy of the cached value from map instead of reference from Hazelcast.getMap() ?

Namely I want a copyOnRead functionality like in EhCache. See EhCache Documentation

emrahkocaman
  • 493
  • 3
  • 12

1 Answers1

2

If you don't use near cache and disable the cache-value. Ex:

 <hz:map name="map"
            backup-count="1"
            max-size="0"
            read-backup-data="true"
            cache-value="false"/>

then Hazelcast will always return you the copy of the actual value no matter what.

If you keep cache-value = true then Hazelcast will cache the object version of the value and will return you the same copy on local reads. By local read I mean the member that read is initiated and the owner of the key is same.

Fuad Malikov
  • 2,325
  • 18
  • 20
  • Thanks @Fuad. That is what I exactly needed.I've noticed that there is a part about "cache-value" in the documentation after your answer but it is in a different chapter (Common Gotchas). It would be great to see this kind of configuration stuff in a related chapter so that they can be easier to find – emrahkocaman May 09 '12 at 11:42