3 Replies Latest reply: Apr 25, 2012 5:06 AM by 902449 RSS

    ConditionalPut always returns null

    902449
      Hi,

      I have a ConditionalPut filter, which I am trying to use like a "putIfAbscent". It goes against a Distributed cache:

      Key baKey = new Key()
      CacheObject cacheObject = new CacheObject (baKey);

      Filter filter = new NotFilter(PresentFilter.INSTANCE);
      CacheObject cacheObject = (CacheObject) getCoherenceCache().invoke(baKey, new ConditionalPut(filter, cacheObject));

      The first time through, cacheObject equals null (as expected)
      The second time through, cacheObject is still null, and my cache size is 2!

      Any ideas?

      Thanks
        • 1. Re: ConditionalPut always returns null
          robvarga
          899446 wrote:
          Hi,

          I have a ConditionalPut filter, which I am trying to use like a "putIfAbscent". It goes against a Distributed cache:

          Key baKey = new Key()
          CacheObject cacheObject = new CacheObject (baKey);

          Filter filter = new NotFilter(PresentFilter.INSTANCE);
          CacheObject cacheObject = (CacheObject) getCoherenceCache().invoke(baKey, new ConditionalPut(filter, cacheObject));

          The first time through, cacheObject equals null (as expected)
          The second time through, cacheObject is still null, and my cache size is 2!

          Any ideas?

          Thanks
          It was a known bug for some older version, I am not sure if they fixed it ever since. Which Coherence version do you use?

          Btw, it is not a difficult task to write a fixed version of ConditionalPut (which also had some issue, IIRC) and ConditionalPutAll.

          Best regards,

          Robert
          • 2. Re: ConditionalPut always returns null
            User738616-Oracle
            Hi,

            This is due to the performance reasons by not returning the object.
            I have a ConditionalPut filter, which I am trying to use like a "putIfAbscent". It goes against a Distributed cache:

            Key baKey = new Key()
            CacheObject cacheObject = new CacheObject (baKey);

            Filter filter = new NotFilter(PresentFilter.INSTANCE);
            CacheObject cacheObject = (CacheObject) getCoherenceCache().invoke(baKey, new ConditionalPut(filter, cacheObject));

            The first time through, cacheObject equals null (as expected)
            The second time through, cacheObject is still null, and my cache size is 2!
            You can use the ConditionalPut API as below to get the returned value:
             CacheObject cacheObject = (CacheObject) getCoherenceCache().invoke(baKey, new ConditionalPut(filter, cacheObject,true));
            Hope this helps!

            Cheers,
            NJ
            • 3. Re: ConditionalPut always returns null
              902449
              Fantastic, this works! However, I do still end up with 2 items in my cache, against 1 key :-S Not even sure how this is possible!

              ** EDIT:- Ignore me, this was a bug on my side. Thanks for your help!

              Edited by: 899446 on 25-Apr-2012 03:06