gpt4 book ai didi

java - 使用 Hibernate 的二级缓存时的默认缓存时间是多少

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:46:01 24 4
gpt4 key购买 nike

当使用 Hibernate 二级缓存和查询缓存并且没有在 ehcache.xml 中指定任何内容时,默认缓存时间是多少?

最佳答案

摘自 Cache Configuration 上的文档:

The following attributes and elements are optional.timeToIdleSeconds:Sets the time to idle for an element before it expires.i.e. The maximum amount of time between accesses before an element expiresIs only used if the element is not eternal.Optional attribute. A value of 0 means that an Element can idle for infinity.The default value is 0.timeToLiveSeconds:Sets the time to live for an element before it expires.i.e. The maximum time between creation time and when an element expires.Is only used if the element is not eternal.Optional attribute. A value of 0 means that and Element can live for infinity.The default value is 0.

Note that EHCache uses a timeToLive, not an expire time and the default is 0 if not specified.


Update: While the above about defaults when configuring a cache is true, it appears that these defaults don't apply if you don't provide any ehcache.xml. So I dug a bit further and I think that EHCache may actually always use a defaultCache in that case - including for the StandardQueryCache - and this defaultCache has a timeToLive of 2 minutes:

<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>

我现在无法确认这一点,但我会这样做:

  • 首先,在 EHCache 上激活日志记录,当使用 defaultCache 时,EHCache 会记录警告:

While the defaultCache is a great convenience, it is preferable for each Cache to be configured individually. For this reason a log warning level message is issued each time a cache is created based on the defaultCache values.

关于java - 使用 Hibernate 的二级缓存时的默认缓存时间是多少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2467466/

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