views:

35

answers:

2

I am using Oracle Coherence cache with Java and am running into an issue. When I put something in the cache (like a map) and get it back using a get call and then modify the object (say, add a value to the map), the modified value is not reflected in the cache. i.e. if I issue a get again, I will get the same old object. This does not occur with ehcache or dynacache.

I know we can write the modified map back to the cache, but I wanted to know if there is some configuration that we can do in the coherence config xml.

Sample code:

ConcurrentHashMap<String, String> myMap = new ConcurrentHashMap<String, String>();
myMap.put("Hello", "World");
cache.put("myMap", myMap);
ConcurrentHashMap<String, String> myExMap = (ConcurrentHashMap<String, String>)cache.get("myMap");
myExMap.put("Once", "More");
ConcurrentHashMap<String, String> myFinMap = (ConcurrentHashMap<String, String>) cache.get("myMap");
System.out.println(myFinMap);

After execution, myFinMap still has only one entry.

A: 

Maybe you have to put the object in the cache every time you modify it (I guess because it is serialized?)

onof
A: 

You must put the object back into the cache. The object got from the Coherence cache is not wrapped in a Coherence class that looks for modifications and synchronizes with the cache.

Jacob Tomaw