<ehcache> <!-- 指定一個目錄:當 EHCache 把數據寫到硬盤上時, 將把數據寫到這個目錄下. --> <diskStore path="d:\\tempDirectory"/> <!-- 設置緩存的默認數據過期策略 --> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" /> <!-- 設定具體的命名緩存的數據過期策略。每個命名緩存代表一個緩存區域 緩存區域(region):一個具有名稱的緩存塊,可以給每一個緩存塊設置不同的緩存策略。 如果沒有設置任何的緩存區域,則所有被緩存的對象,都將使用默認的緩存策略。即:<defaultCache.../> Hibernate 在不同的緩存區域保存不同的類/集合。 對於類而言,區域的名稱是類名。如:com.atguigu.domain.Customer 對於集合而言,區域的名稱是類名加屬性名。如com.atguigu.domain.Customer.orders --> <!-- name: 設置緩存的名字,它的取值為類的全限定名或類的集合的名字 maxElementsInMemory: 設置基於內存的緩存中可存放的對象最大數目 eternal: 設置對象是否為永久的, true表示永不過期, 此時將忽略timeToIdleSeconds 和 timeToLiveSeconds屬性; 默認值是false timeToIdleSeconds:設置對象空閑最長時間,以秒為單位, 超過這個時間,對象過期。當對象過期時,EHCache會把它從緩存中清除。如果此值為0,表示對象可以無限期地 處於空閑狀態。 timeToLiveSeconds:設置對象生存最長時間,超過這個時間,對象過期。如果此值為0,表示對象可以無限期地存在於緩存中.
該屬性值必須大於或等於 timeToIdleSeconds 屬性值 overflowToDisk:設置基於內存的緩存中的對象數目達到上限后,是否把溢出的對象寫到基於硬盤的緩存中 --> <cache name="com.atguigu.hibernate.entities.Employee" maxElementsInMemory="1" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="true" /> <cache name="com.atguigu.hibernate.entities.Department.emps" maxElementsInMemory="1000" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" /> </ehcache>