Search code examples
cachinginfinispanjboss-eap-6jboss-cache

Jboss eap-6.3 caching configuration


How we can configure cache in jboss eap 6.3 server and use it in further different application like j2ee etc

Please assist here .. !!


Solution

  • Caching using jboss eap configuration:

    Steps

    1) subsystem inside standalone-ha.xml of jboss eap 6.3

     <subsystem xmlns="urn:jboss:domain:infinispan:1.5">
                <cache-container name="DataCacheContainer" aliases="demo" default-cache="EdgeCache" start="EAGER" module="org.jboss.as.clustering.infinispan">
                    <transport lock-timeout="60000"/>
                    <replicated-cache name="EdgeCache" mode="ASYNC" batching="true">
                        <eviction strategy="LRU" max-entries="250000"/>
                        <file-store/>
                    </replicated-cache>
                    <replicated-cache name="SubdivCache" mode="SYNC" batching="true">
                        <eviction strategy="LIRS" max-entries="25000"/>
                        <file-store/>
                    </replicated-cache>
                </cache-container>
                <cache-container name="LocatorCacheContainer" default-cache="trainLocatorCache">
                    <local-cache name="LocatorCache"/>
                </cache-container>
                <cache-container name="ScheduleCacheContainer" default-cache="tgeoControlPtCache">
                    <local-cache name="ControlPtCache"/>
                </cache-container>
                <cache-container name="singleton" aliases="cluster ha-partition" default-cache="default">
                    <transport lock-timeout="60000"/>
                    <replicated-cache name="default" mode="SYNC" batching="true">
                        <locking isolation="REPEATABLE_READ"/>
                    </replicated-cache>
                </cache-container>
                <cache-container name="web" aliases="standard-session-cache" default-cache="repl" module="org.jboss.as.clustering.web.infinispan">
                    <transport lock-timeout="60000"/>
                    <replicated-cache name="repl" mode="ASYNC" batching="true">
                        <file-store/>
                    </replicated-cache>
                    <replicated-cache name="sso" mode="SYNC" batching="true"/>
                    <distributed-cache name="dist" l1-lifespan="0" mode="ASYNC" batching="true">
                        <file-store/>
                    </distributed-cache>
                </cache-container>
                <cache-container name="ejb" aliases="sfsb sfsb-cache" default-cache="repl" module="org.jboss.as.clustering.ejb3.infinispan">
                    <transport lock-timeout="60000"/>
                    <replicated-cache name="repl" mode="ASYNC" batching="true">
                        <eviction strategy="LRU" max-entries="10000"/>
                        <file-store/>
                    </replicated-cache>
                    <replicated-cache name="remote-connector-client-mappings" mode="SYNC" batching="true"/>
                    <distributed-cache name="dist" l1-lifespan="0" mode="ASYNC" batching="true">
                        <eviction strategy="LRU" max-entries="10000"/>
                        <file-store/>
                    </distributed-cache>
                </cache-container>
    

    2) Lookup of these cache container from code using url:

     private static Cache<Integer, DataObject> cache;
        private static Cache<String, Integer> DivCache;
    
    
                InitialContext ic = new InitialContext();
    
                CacheContainer cc = (CacheContainer)    ic.lookup("java:jboss/infinispan/container/DataCacheContainer");
    
                cc.start();
    
                cache = cc.getCache("EdgeCache");
                divCache = cc.getCache("SubDivCache");
                cache.start();
                divCache.start();
    
                logger.info("Cache Objects started successfully...");
    

    3) Now you can store data in these cache objects.

    cache.put("one", "two"); divCache.put("three","four");