摘自缓存配置文档:
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"
/>
Run Code Online (Sandbox Code Playgroud)
我现在无法确认这一点,但这就是我要做的:
虽然defaultCache非常方便,但最好每个Cache单独配置.因此,每次根据defaultCache值创建缓存时,都会发出日志警告级别消息.