10 Replies Latest reply on Jul 24, 2014 5:13 PM by Alexey Olenev

    Cache.put() triggers CacheStore.load()

    Alexey Olenev Newbie

      Hi,

      I'm using Infinispan 7.0.0.Alpha4 and faced with strange behaviour: if I put object in cache it triggers cacheStore.load(). Snippet from my configuration:

      <distributed-cache name="string-cache" owners="2" mode="SYNC">
                  <state-transfer enabled="true" />
                  <persistence>
                      <store class="org.sproot_grid.infinispan.cachestore.StringCacheStore">
                          <property name="driver">org.h2.Driver</property>
                          <property name="connection-url">jdbc:h2:mem:testdb</property>
                          <property name="username">sa</property>
                          <property name="password"></property>
                      </store>
                  </persistence>
              </distributed-cache>
      
      

      StringCacheStore - is my implementation of CacheLoader and CacheWriter

       

      I found possible reason here (org.infinispan.factories.InterceptorChainFactory):

      if (configuration.persistence().usingStores()) {
               if (configuration.persistence().passivation()) {
                  if (configuration.clustering().cacheMode().isClustered())
                     interceptorChain.appendInterceptor(createInterceptor(new ClusteredActivationInterceptor(), ClusteredActivationInterceptor.class), false);
                  else
                     interceptorChain.appendInterceptor(createInterceptor(new ActivationInterceptor(), ActivationInterceptor.class), false);
               } else {
                  if (configuration.clustering().cacheMode().isClustered())
                     interceptorChain.appendInterceptor(createInterceptor(new ClusteredCacheLoaderInterceptor(), ClusteredCacheLoaderInterceptor.class), false);
                  else
                     interceptorChain.appendInterceptor(createInterceptor(new CacheLoaderInterceptor(), CacheLoaderInterceptor.class), false);
                  switch (configuration.clustering().cacheMode()) {
                     case DIST_SYNC:
                     case DIST_ASYNC:
                     case REPL_SYNC:
                     case REPL_ASYNC:
                        interceptorChain.appendInterceptor(createInterceptor(new DistCacheWriterInterceptor(), DistCacheWriterInterceptor.class), false);
                        break;
                     default:
                        interceptorChain.appendInterceptor(createInterceptor(new CacheWriterInterceptor(), CacheWriterInterceptor.class), false);
                        break;
                  }
               }
            }
      
      

       

      Why do we need CacheLoaderInterceptor here (despite command is PutKeyValueCommand)?

      Moreover it fails with NPE if there is no entry with given key in underlying persistent storage (UPDATE: NPE is fixed, I just had to return null from CacheLoader if nothing found instead of wrapping null into MarshalledEntry).

      Can I disable such a workflow by declarative configuration?