使用hibernate时的默认缓存时间

com*_*tta 8 java caching hibernate ehcache

当使用hibernate二级缓存和查询缓存而没有在ehcache.xml中指定任何内容时.默认的缓存时间是什么?

Pas*_*ent 9

摘自缓存配置文档:

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)

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

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

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

  • 缓存配置链接是404 (2认同)