views:

96

answers:

1

when using hibernate 2nd level cache and query cache and not specifying anything inside ehcache.xml .what is the default caching time?

+1  A: 

Taken from the documentation on 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.

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"
        />

I can't confirm this right now but this is what I would do:

  • first, activate logging on EHCache, EHCache logs a warning when the defaultCache is used:

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.

Pascal Thivent
i have a page using 2nd level +cache query. the caching work fine because when i do refresh the show_sql not showing sql query. but after like 4-5min after i press refresh, it show the query is retrieving from db. from you explanation the default is '0' but doesnt look like it. can elaborate?
cometta