4 Replies Latest reply on Jan 18, 2012 7:59 AM by Sudheer Krishna

    Cache Listeners post event call returning old values(for 100 milliseconds) instead of updated values

    Sudheer Krishna Novice

      Hi,

       

      I am using Infinispan 5.0.0.FINAL version.

       

      i am using cache listeners to get event notifications which are happening in a transaction. I use teh following code

       

          @CacheEntryCreated

          @CacheEntryModified

          @CacheEntryRemoved

          public void cacheChangeEvent(CacheEntryEvent<Long, MyPojo> event) {

              logger.debug("Cache change event called : {}", event.getType().toString());

              try {

                  if (!event.isPre()) {

                      MyPojo pojo = event.getCache().get(event.getKey());

                      logger.debug("value", pojo);

                  }

              } catch (Exception e) {

              }

          }

       

      BUt teh issue issue i see is i  get old value even though i check its a post event call.

       

       

      When i put a sleep of 100 milliseconds everything seems to work fine. IS it a know issue/bug ? OR Am i doing anything wrong ?

       

       

      working code

       

          @CacheEntryCreated

          @CacheEntryModified

          @CacheEntryRemoved

          public void cacheChangeEvent(CacheEntryEvent<Long, MyPojo> event) {

              logger.debug("Cache change event called : {}", event.getType().toString());

              try {

                  if (!event.isPre()) {

                      Thread.sleep(100);   -> this ensures that updated valued is obtained .

                      MyPojo pojo = event.getCache().get(event.getKey());

                      logger.debug("value", pojo);

                  }

              } catch (Exception e) {

              }

          }