ehcache.xml文件:
下載ehcache,hibernate3.2必須要ehcache1.2以上才能支持。可以修改log4j配置文件log4j.logger.net.sf.hibernate.cache=debug查看日志
< ehcache>
< diskStore path="c:\\ehcache\"/>
< defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
/>
< !-- 設(shè)置Category類的緩存的數(shù)據(jù)過期策略 -->
< cache name="org.qiujy.domain.cachedemo.Category"
maxElementsInMemory="100"
eternal="true"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"
/>
< !-- 設(shè)置Category類的products集合的緩存的數(shù)據(jù)過期策略 -->
< cache name="org.qiujy.domain.cachedemo.Category.products"
maxElementsInMemory="500"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="true"
/>
< cache name="org.qiujy.domain.cachedemo.Product"
maxElementsInMemory="500"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="true"
/>
< /ehcache>
配置的元素說明:
元素或?qū)傩?描述
< diskStore> 設(shè)置緩存數(shù)據(jù)文件的存放目錄
< defaultCache> 設(shè)置緩存的默認(rèn)數(shù)據(jù)過期策略
< cache> 設(shè)定具體的命名緩存的數(shù)據(jù)過期策略
每個(gè)命名緩存代表一個(gè)緩存區(qū)域,每個(gè)緩存區(qū)域有各自的數(shù)據(jù)過期策略。命名緩存機(jī)制使得用戶能夠在每個(gè)類以及類的每個(gè)集合的粒度上設(shè)置數(shù)據(jù)過期策略。
cache元素的屬性
name 設(shè)置緩存的名字,它的取值為類的全限定名或類的集合的名字
maxInMemory 設(shè)置基于內(nèi)存的緩存中可存放的對(duì)象最大數(shù)目
eternal 設(shè)置對(duì)象是否為永久的,true表示永不過期,此時(shí)將忽略timeToIdleSeconds和timeToLiveSeconds屬性;
默認(rèn)值是false
timeToIdleSeconds 設(shè)置對(duì)象空閑最長(zhǎng)時(shí)間,超過這個(gè)時(shí)間,對(duì)象過期。當(dāng)對(duì)象過期時(shí),EHCache會(huì)把它從緩存中清除。
如果此值為0,表示對(duì)象可以無限期地處于空閑狀態(tài)。
timeToLiveSeconds 設(shè)置對(duì)象生存最長(zhǎng)時(shí)間,超過這個(gè)時(shí)間,對(duì)象過期。
如果此值為0,表示對(duì)象可以無限期地存在于緩存中。
overflowToDisk 設(shè)置基于內(nèi)在的緩存中的對(duì)象數(shù)目達(dá)到上限后,是否把溢出的對(duì)象寫到基于硬盤的緩存中
------君臨天下,舍我其誰(shuí)
------