2014-02-08 46 views
0

在我的項目中,我們使用ehcache進行二級緩存,我們也提到<defaultCache>標籤和一些<cache>屬性。Ehcache與defaultCache?

樣品 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> 

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

這裏

我們已經增加了<class-cache>標記爲com.test.Third,這是不是在ehcache.xml文件中提及。

這個com.test.Third類也可以通過使用defaultCache來緩存嗎?

回答

1

事實上,它會爲這種情況,因爲休眠會爲你做的工作。但defaultCache並非專門用於創建自動緩存。對於更多的細節,請檢查這個問題:Do caches in ehcache.xml inherit from defaultCache?和這個問題:EhCache default cache in java

+0

Thaks @Nick,但令我驚訝com.test.Third也因爲。謝謝。 –

+0

我想Hibernate爲你做了創作工作。對於Hibernate 4.3.3,org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory中的getCache(String name)會以編程方式添加緩存(如果不存在)。無論如何,我已經調整了我的答案... – Nick