gpt4 book ai didi

java - 在 persistence.xml 中缓存区域配置

转载 作者:行者123 更新时间:2023-11-30 11:19:56 25 4
gpt4 key购买 nike

根据 this documentation ,当将 Infinispan 与 Hibernate 一起使用时,可以定义多个缓存区域并单独配置它们。我使用的是 WildFly 8.0,它使用 Infinispan 作为 Hibernate 的默认 2LC 提供程序。所以这是我的 hibernate 缓存容器的 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 秒。我在这里缺少什么?

最佳答案

正如 Galder Zamarreño 在评论中提到的,必须将部署名称添加到区域中。

或者,您可以将 prefix 显式设置为空 ("") 或如下所示的某个值。

<property name="hibernate.cache.region_prefix" value="my-cache"/> 

然后如下指定区域prefix

<property name="hibernate.cache.infinispan.my-cache.myRegionName.expiration.max_idle" value="5000"/>

关于java - 在 persistence.xml 中缓存区域配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23009956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com