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?

Ramesh Kotha
  • 8,266
  • 17
  • 66
  • 90

1 Answers1

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

Community
  • 1
  • 1
Nick
  • 324
  • 4
  • 14
  • Thaks @Nick, but to my surprise com.test.Third also getting cached just because of . Thanks. – Ramesh Kotha May 28 '14 at 17:43
  • 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... – Nick May 29 '14 at 14:26