我在 JBoss 7 中通过 CLI 添加了缓存:
/subsystem=infinispan/cache-container=sample:add
/subsystem=infinispan/cache-container=sample/replicated-cache=account:add(mode=ASYNC)
/subsystem=infinispan/cache-container=sample/replicated-cache=account/component=transaction:write-attribute(name=mode,value=BATCH)
/subsystem=infinispan/cache-container=sample/replicated-cache=account/component=locking:write-attribute(name=isolation, value=REPEATABLE_READ)
看到它反射(reflect)在standalone.xml的Infinispan子系统中:
<cache-container name="sample">
<replicated-cache name="account" mode="ASYNC">
<locking isolation="REPEATABLE_READ"/>
<transaction mode="BATCH"/>
</replicated-cache>
</cache-container>
在 JBoss 控制台中看到它的反射(reflect):
但是在应用程序内部使用时,找到了缓存容器,但没有找到缓存。相反,当使用不同的设置调用 cacheManager#getCache
时,它会被延迟创建。
模式集是复制的,但找到的是本地的。其他设置(例如交易)也有所不同。我错过了什么吗?
最佳答案
我遇到了和你非常相似的问题。我在 EAP 7 中有一个配置了生命周期的本地缓存。它被配置为相对较短。相同的配置之前运行良好,但我们意识到,缓存的内容永远保留在缓存中。
问题在于我们如何获取缓存实例。我们注入(inject)了缓存管理器:
@Resource(lookup = "java:jboss/infinispan/download-manager")
private CacheContainer cacheContainer;
然后我们使用缓存容器来访问缓存。调试后,尽管 EAP 7 中的生命周期仅为 30 秒,但生命周期为 -1。
cacheContainer.getCache("someCache")
没有获取缓存的实例,而是创建了一个具有默认值的新缓存。我认为它解释了您的“本地缓存”仅设置。
我如何使用正确的设置访问缓存的方式是:
@Resource(lookup = "java:jboss/infinispan/cache/download-manager/someCache")
private Cache<String, Object> negative_cache_direct;
关于java - JBoss EAP 7.0standalone.xml 中设置的 Infinispan 缓存设置未反射(reflect)在应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46598738/