1

I'm using Wildfly 10.1.0 + Infinispan 8.2.4.Final + cache API 1.0.0 trying to enable Infinispan Jcache Interceptors in my application with minimum efforts, with no programmatic setup if possible. I wanted to make such an annotation work to store some dictionaries:

@CacheResult(cacheName = "dictionary", cacheKeyGenerator = MyCacheKeyGeneratorImpl.class)  
public List getDictionary() {  
   ...  
}  

I initially started this activity because I missed Spring @Cacheable annotations (we currently don't use Spring config/CDI, just a few libraries like Spring Data JPA Repositories). So I downloaded Infinispan Wilfly/EAP module, unpacked it to Wilfly modules folder and added this to jboss-deployment-structure.xml:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
  <deployment>
  <dependencies>
  <module name="org.infinispan" slot="ispn-8.2" services="export"/>
  <module name="org.infinispan.cdi" slot="ispn-8.2" services="export"/>
  <module name="org.infinispan.jcache" slot="ispn-8.2" services="export"/>
  </dependencies>
  </deployment>
</jboss-deployment-structure>

Now the annotations are processed and some default cache container is used to create "dictionary" cache. Now I want to fine-tune this cache container. What's the common way to inject infinispan configuration? Is it possible to plug the module settings into the main Wilfly configuration file (standalone.xml) to define this cache container like this, or specify them in a separate file?

<cache-container name="JCacheContainer" default-cache="default" module="org.infinispan.jcache">
  <local-cache name="default">
   <transaction mode="NONE"/>
   <eviction strategy="LRU" max-entries="1000"/>
   <expiration max-idle="3600000"/>
  </local-cache>
  <local-cache name="dictionary">
   <locking acquire-timeout="15000" isolation="REPEATABLE_READ"/>
   <transaction locking="PESSIMISTIC" mode="NONE"/>
   <eviction strategy="LRU" max-entries="100000"/>
   <expiration lifespan="15000" max-idle="15000"/>
  </local-cache>
</cache-container>

Any help is very much appreciated.

4

1 回答 1

2

在Infinispan 集成测试中可以找到此类配置的工作示例。唯一的区别是 Infinispan 部署在 WAR 文件中,而不是放在模块中。

您需要做的就是放入infinispan.xmlWEB-INF 目录并使用正确的beans.xml.

另一个使用模块和 CDI 的例子可以在JBoss Data Grid Quickstarts中找到。该示例中唯一缺少的部分是 JCache。

最后,您可能会对Infinispan 用户指南中的JCache 文档段落感兴趣。

于 2017-12-07T09:58:37.310 回答