Hibernate+EhCache配置二級緩衝

來源:互聯網
上載者:User

標籤: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配置二級緩衝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.