繁体   English   中英

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

[英]What is the default caching time when using Hibernate's 2nd level cache

当使用 Hibernate 2nd level 缓存和查询缓存并且没有在ehcache.xml指定任何ehcache.xml ,默认缓存时间是多少?

取自缓存配置文档:

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 expires
Is 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.

请注意,EHCache 使用的是 timeToLive,而不是过期时间,如果未指定,则默认值为 0。


更新:虽然上面关于配置缓存时的默认值是正确的,但如果您不提供任何ehcache.xml ,这些默认值似乎不适用。 所以我进一步挖掘,我认为 EHCache 在这种情况下实际上可能总是使用defaultCache - 包括StandardQueryCache - 并且这个 defaultCache 的 timeToLive 为 2 分钟:

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

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

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

虽然 defaultCache 非常方便,但最好单独配置每个 Cache。 因此,每次基于 defaultCache 值创建缓存时都会发出日志警告级别消息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM