使用hibernate二级缓存和查询缓存,未在ehcache.xml中指定任何内容。默认缓存时间是什么时候?
答案 0 :(得分:9)
取自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 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。
更新:虽然上面关于配置缓存的默认值为true,但如果您不提供任何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"
/>
我现在无法确认这一点,但这就是我要做的事情:
虽然defaultCache非常方便,但最好每个Cache单独配置。因此,每次根据defaultCache值创建缓存时,都会发出日志警告级别消息。