简体   繁体   中英

Ehcache with defaultCache?

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM