1 Reply Latest reply on May 28, 2016 4:50 PM by wdfink

    Datagrid in shared mode

    kotak25krishna

      I am trying to use data grid in library mode to enable shared cache between war modules. I have configured Cache in WAR1, placed a key in the cache. Now I am trying to read the same key from WAR2, which is null.

      Want to understand is there any additional configuration I have to do to enable data grid in shared mode.

      Looking your suggestion/recommendation on overcoming this.

      I am using JBOSS EAP 6.4.5

      Here below is the same code I am using to configure cache in WAR1

       

       

      GlobalConfigurationBuilder cb = new GlobalConfigurationBuilder();

        cb.globalJmxStatistics().allowDuplicateDomains(true).build();

       

       

        ConfigurationBuilder cb1 = new ConfigurationBuilder();

        cb1.eviction().strategy(EvictionStrategy.LIRS).maxEntries(30000).build();

        EmbeddedCacheManager dcm = new DefaultCacheManager(cb.build(),cb1.build());

        dcm.start();

        Cache<Object,Object> c = dcm.getCache("test-cache");

        c.put("Test", "Test data kept in cache");

        • 1. Re: Datagrid in shared mode
          wdfink

          I guess you have two war files and add the library to the war, the cache is a different instance (classloader, configuration ...)

          So one option is to configure JGroups for both to build a cluster. If you have both war files in the same JVM this might be an overhead as you have two copies of the entries.

          Second option is to have a third application which contain the cache and access the CacheManager via EJB access or bind a JNDI entry (this only works i´within the same JVM)