0

In my project we are using ehcache for second level caching, We mentioned <defaultCache> tag and some <cache> attributes as well.

sample of ehcache.xml

<ehcache> <defaultCache maxEntriesLocalHeap="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" maxEntriesLocalDisk="10000000" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" /> <cache name="com.test.First" maxEntriesLocalHeap="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" /> <cache name="com.test.Second" maxEntriesLocalHeap="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" /> </ehcache> 

sample of hibernate.cfg.xml

<class-cache class="com.test.First" usage="read-only"/> <class-cache class="com.test.Second" usage="read-only"/> <class-cache class="com.test.Third" usage="read-only"/> 

here we have added <class-cache> tag for com.test.Third, which is not mentioned in ehcache.xml file.

Will this com.test.Third class also be cached by using defaultCache?

1 Answer 1

1

Actually it will for this case, because Hibernate will do the work for you. But the defaultCache is not designed for creating cache automatically. For more details please check this question: Do caches in ehcache.xml inherit from defaultCache? and this question: EhCache default cache in java

Sign up to request clarification or add additional context in comments.

2 Comments

Thaks @Nick, but to my surprise com.test.Third also getting cached just because of <class-cache class="com.test.Third" usage="read-only"/>. Thanks.
I guess Hibernate did the creation work for you. For Hibernate 4.3.3, the getCache(String name) inside org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory will add cache programatically if it's absence. Anyway, I had adjusted my answer...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.