1

The last few days I take a look to use infinispan to manage a cache with my applications. I have some ears applications that runs on same wildfly and my purpose is to have a local cache that all my application can use. This cache will not be shared between the nodes. My intention was to use infinspan with jcache, so in this manner I can annotate my functions to cache the result. I'm not interested in a replicated cache, because the data that I'm going to cache will be evicted every 5 minutes and the data will not be duplicated on the nodes (the session of the client is persisted and the clients call these function with differente key value a lot of times).

I'm using wildlfy 14 with the standalone-full profile and I took some look into the documentation online. I added a new cache container to the configuration system, also via the cli

/subsystem=infinispan/cache-container=container-name:add
/subsystem=infinispan/cache-container=container-name/local-cache=container-name-default:add
/subsystem=infinispan/cache-container=container-name/local-cache=container-name-sd:add

I see that the container and the cache are not published with jndi and using the wildfly console I can't find the added caches in the jndi runtime string. Without the jndi string, I can't access to the cache.

Becasue at first moment my intenction was to use JCache, I found the documentation on infinispan website to add the complete module of infinispan to wildlfy. To use the module donwloaded, I extended wildfly with the infinispan module in extensions tag section. Using the standalone full profile, I had some errors with the access to the cache and the @CacheResult annotation wasn't fired, also with the beans.xml defined with the interceptors

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" version="1.1" bean-discovery-mode="all">
<interceptors>
     <class>org.infinispan.jcache.annotation.InjectedCacheResultInterceptor</class>
     <class>org.infinispan.jcache.annotation.InjectedCachePutInterceptor</class> 
     <class>org.infinispan.jcache.annotation.InjectedCacheRemoveEntryInterceptor</class>
     <class>org.infinispan.jcache.annotation.InjectedCacheRemoveAllInterceptor</class> 
</interceptors>

At the end I found that using standalone ha wildfy profile and adding a jgroup to the cache container, I'm able to publish the cache with a jndi string and use it.

Is there a simple method to create and access a local cache with infinispan and wildfly 14? Do someone can provide an example with an ear application? Is it correct that I need to use the ha profile to define new cache container with jgroups? I found that in the full wildfly profile, the infinispan cache is usde only for internal use, so it is necessary to use the ha profile as I said before.

Thanks for every answer and I hope I was enough clear.

balax85
  • 36
  • 2
  • Not sure if it helps, but Infinispan uses [Caffeine](https://github.com/ben-manes/caffeine) for its in-memory cache. If you don't want the extras that Infinispan brings, you find it simpler to use that library instead. – Ben Manes Jun 25 '19 at 02:21
  • Thanks Ben for the answer. I will take a look on it, but at a first look it seem that I need to create the cache programmatically in the application. My intention was to use the integrated cache in Wildlfy with Infinispan, so I can also inject and share cache between some ear application. I was using infinispan so I can define the cache parameters on the wildfly standalone configuration also. – balax85 Jun 25 '19 at 06:25
  • The Infinispan version that comes in WildFly only contains the modules that are needed for internal WildFly uses, hence why things like JCache integration are not there. Having said that, the best thing for own use is to add Infinispan and its dependencies to your own deployment and then you're in full control of things and don't have to fiddle with JNDI and stuff. Sebastian shows an example of what you want to do here: https://blog.sebastian-daschner.com/entries/caching-method-results-jcache – Galder Zamarreño Jun 27 '19 at 11:19
  • Yes, I understand. In fact i added to my wildfly the infinspan modules downloaded from his website, with all dependencies about cdi and jcache. Probably the fast method to use jcache is the example that you put on your answe, but in this manner the cache can't be used in different ear project, it is not a shared cache. I will take a look on you link and I will take some test. Thanks Galder – balax85 Jun 28 '19 at 12:24

0 Answers0