【发布时间】:2014-05-25 10:53:03
【问题描述】:
根据 this documentation 的说法,当使用 Infinispan 和 Hibernate 时,可以定义多个缓存区域并单独配置它们。我正在使用 WildFly 8.0,它使用 Infinispan 作为 Hibernate 的默认 2LC 提供程序。所以这是我对休眠缓存容器的standalone.xml配置:
<cache-container name="hibernate" default-cache="local-query" module="org.hibernate">
<local-cache name="entity">
<transaction mode="NON_XA"/>
<eviction strategy="LRU" max-entries="10000"/>
<expiration max-idle="100000"/>
</local-cache>
<local-cache name="local-query">
<transaction mode="NONE"/>
<eviction strategy="LRU" max-entries="10000"/>
<expiration max-idle="100000"/>
</local-cache>
<local-cache name="timestamps">
<transaction mode="NONE"/>
<eviction strategy="NONE"/>
</local-cache>
</cache-container>
因此,最长空闲过期时间设置为 100 秒。这就是我告诉 Hibernate 缓存查询的方式:
slotQuery.setHint("org.hibernate.cacheable", true)
.setHint("org.hibernate.cacheRegion", "myRegionName")
.getResultList();
一切正常,查询被缓存 100 秒。但是当我尝试在 persistence.xml 中为查询配置单独的缓存区域时:
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.infinispan.myRegionName.expiration.max_idle" value="5000"/>
设置未被覆盖,查询被缓存 100 秒。我在这里错过了什么?
【问题讨论】:
-
在应用服务器内部运行时,需要添加部署名称,即
hibernate.cache.infinispan.<warname>.<unitname>.<FQN of entity>.expiration.max_idle。你可以试试这个吗?
标签: java hibernate caching persistence infinispan