4 Replies Latest reply on Apr 26, 2016 6:38 PM by barbazor

    Unexpected behaviour of infinispan local cache in Wildfly 10.

    valsitsar

      Hi friends,

      this is my first post here and I must say I am looking forward to be member of this forum

       

      So, what is the problem I am trying to solve? I am struggling with the configuration of the infinispan local cache. Especially with the configuration of "max-entries". In the previous version of Wildfly, the "max-entries" was doing exactly what I have expected - it was not possible to enter more entries than max-entries value. On the other hand, in the WF 10 it seems that is is possible. At least with the configuration I have in the standalone.xml

       

      <cache-container name="myCacheContainer">
          <local-cache name="myCache">
              <eviction strategy="LRU" max-entries="2"/>
              <expiration lifespan="600000"/>
          </local-cache>
      </cache-container>
      

       

      My testing scenario was that I was accessing instance of MyCache to add value to the cache using some REST endpoint. Then I was using another REST endpoint to display the content of MyCache. In the previous version of Wildfly, I was able to add exactly 2 entries. Adding third one caused the first one to be replaced. In Wildfly 10, the number of entries keeps growing like if there is no limit for it.

       

      The way I am using the cache in code is pretty standard. Here is MyCache class:

       

      @ManagedBean
      @Singleton
      @Named("myCache")
      public class MyCache implements IMyCache<String, String> {
      
        @Resource(lookup = "java:jboss/infinispan/container/myCacheContainer")
        protected EmbeddedCacheManager container;
        private Cache<String, String> cache;
      
        @PostConstruct
        @Override
        public void init() {
          this.cache = container.getCache("myCache");
        }
          ...
       }
      

       

      MyCache class is then injected to the class with REST resources where it is a part of some business logic.

       

      I would appreciate any suggestions or hints how to fix this.

      Thanks

        • 1. Re: Unexpected behaviour of infinispan local cache in Wildfly 10.
          pferraro

          Injecting the cache container doesn't imply that the "myCache" is available - thus the cache that is returned by container.getCache("myCache") was not built using the configuration you expect.  Use this instead:

          @Resource(lookup = "java:jboss/infinispan/cache/myContainer/myCache")
          private Cache<String, String> cache;
          

           

          The lifecycle of the cache resource will be handled by the container.

          • 2. Re: Unexpected behaviour of infinispan local cache in Wildfly 10.
            barbazor

            Hi,

             

            I read this post and this JIRA https://issues.jboss.org/browse/WFLY-5959, also https://developer.jboss.org/thread/259151 and i get

             

            Caused by: javax.naming.NameNotFoundException: infinispan/cache/myCache/cachedb
            
            

             

            This is my code:

             

            @Singleton
            @Startup
            @AccessTimeout(value = 5, unit = TimeUnit.MINUTES)
            public class ProcessManager {
            
                @Resource(lookup = "java:jboss/infinispan/cache/myCache/cachedb")
                private Cache<String, String> cache;
            

             

            I change lookup parameter with:

             

            java:jboss/infinispan/cache/myCache/cachedb
            java:jboss/infinispan/cache/myCache
            java:jboss/infinispan/container/myCache/cachedb
            java:jboss/infinispan/container/myCache
            
            

             

            i get another exceptions but finally it didn't work.

             

            In ear META-INF i add:

             

            Dependencies: org.infinispan export
            
            

             

            This is my standalone.xml configuration:

             

            <cache-container name="myCache" default-cache="cachedb">
               <local-cache name="cachedb" jndi-name="java:/jboss/infinispan/cache/myCache/cachedb">
                  <transaction locking="PESSIMISTIC" mode="NON_XA"/>
               </local-cache>
            </cache-container>
            
            

             

            I try with and without jndi-name. Also i try <resource-env-ref> and it didn't work.


            Any help will be appreciated.

            • 3. Re: Unexpected behaviour of infinispan local cache in Wildfly 10.
              barbazor

              I make it works, i change javax.inject.singleton by javax.ejb.singleton. I think @Startup doesn't work with javax.inject.singleton and when i change to ejb, it initialize the singleton at application startup.