1 Reply Latest reply on Jan 30, 2013 4:00 AM by Sanne Grinovero

    Mutable objects update by reference in Infinispan

    tomas11 Novice

      Is there some good approach which would cover next scenario?


      1. We have two nodes with Cache<String, String> testCache

      2. Node1: testCache.put("1", "test")

      3. Node2: testCache.get("1") - "test"

      4. Node2: String text = testCache.get("1");

                                 text = "changed test";

      5. Node1: testCache.get("1") - "test"


      Basically what I would like to achieve is change in cache by reference. In step 5. I would like get text = "changed test";


      Currently I think changes are only propagated only when testCache.put() is invoked. Is there any approach with which I can do changes to mutable object only by reference without invoking put command on cache?



        • 1. Re: Mutable objects update by reference in Infinispan
          Sanne Grinovero Master


          no you can't do that, especially with String instances ;-)


          It won't work either with mutable objects, as Infinispan won't know if/when it has to propagate the change from the in-memory instance to the CacheStores or to other nodes.


          If you need to "track" objects for changes and the Hibernate API suites you, you could use Hibernate OGM:


          1- begin transaction

          2- load some mutable entity A

          3- pass A to other functions which optionally make some change

          4- commit transaction -> At this point if any field changed on the mutable entity this is made visible to other threads on the same JVM and also other nodes on different JVMs.