標籤:tmp 磁碟 fifo nal evel esc 緩衝 span lru
步驟:
第一步:加入ehcache.jar
第二步: 在src目錄下建立一個檔案,名為:ehcache.xml
第三步:在hibernate設定檔的<session-factory>下配置
配置的具體資訊:
ehcache.xml的具體配置:
<?xml version="1.0" encoding="UTF-8"?><!-- maxEntriesLocalHeap: 在記憶體中緩衝的element的最大數目。 maxEntriesLocalDisk: 在磁碟上緩衝的element的最大數目,預設值為0,表示不限制。 eternal: 設定緩衝的elements是否永遠不到期。如果為true,則緩衝的資料始終有效, 如果為false那麼還要根據timeToIdleSeconds,timeToLiveSeconds判斷。 timeToIdleSeconds="10" 緩衝空閑時間 預設值0 一直存活 timeToLiveSeconds="15" 緩衝最大存活時間 預設值0 一直存活 diskExpiryThreadIntervalSeconds:磁碟資料的有效時間 memoryStoreEvictionPolicy="LFU" FIFO ,first in first out (先進先出). LFU , Less Frequently Used (最少使用).意思是一直以來最少被使用的。緩衝的元素有一個hit 屬性,hit 值最小的將會被清出緩衝。 LRU ,Least Recently Used(最近最少使用). (ehcache 預設值).緩衝的元素有一個時間戳記,當緩衝容量滿了, 而又需要騰出地方來緩衝新的元素的時候,那麼現有緩衝元素中時間戳記離目前時間最遠的元素將被清出緩衝。 <persistence strategy="localTempSwap"/> 記憶體存滿後將資料存入硬碟 --><ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd"> <!-- <diskStore path="java.io.tmpdir"/> --> <diskStore path="E:\\cache4"/> <defaultCache maxEntriesLocalHeap="2" maxEntriesLocalDisk="10000000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" diskSpoolBufferSizeMB="30" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU"> <persistence strategy="localTempSwap"/> </defaultCache></ehcache>
在hibernate中的配置:
<!-- 開啟二級緩衝 --> <property name="hibernate.cache.use_second_level_cache">true</property> <!-- 二級緩衝類別:EhCache,OSCache,JbossCache --> <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
Hibernate+EhCache配置二級緩衝