閑人野居
          好好學(xué)習(xí),天天向上
          posts - 57,  comments - 137,  trackbacks - 0
          欠了很久的文章,本來(lái)都不想發(fā)了,可還是發(fā)吧

          ehcache的默認(rèn)配置文件名為ehcache.xml,也可以自己指定。配置文件比較的簡(jiǎn)單,基本上也就是常用的幾個(gè)元素。

          配置元素說(shuō)明:

          diskStore:配置DiskStore,當(dāng)需要使用磁盤保存的時(shí)候,需要對(duì)象實(shí)現(xiàn)序列化接口

              屬性:path 配置文件存儲(chǔ)位置,如user.home,user.dir,java.io.tmpdir

          cacheManagerEventListenerFactory :指定CacheManagerEventListenerFactory,用于創(chuàng)建CacheManagerPeerProvider

          用于提醒當(dāng)CacheManager中的緩存增加或者刪除時(shí)。
             
              屬性:class:完整的工廠類名稱
                   properties:逗號(hào)分割的屬性

          事件包括 增加cache和刪除cache

          cacheManagerPeerProviderFactory:指定CacheManagerPeerProviderFactory,用于創(chuàng)建CacheManagerPeerProvider,用于在cluster中查找CacheManagers,主要用于機(jī)群環(huán)境

              屬性:
                  class:完整的工廠類名稱
                  properties:逗號(hào)分割的屬性

          默認(rèn)的配置:
           
          <cacheManagerPeerProviderFactory
                                          class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
                                          properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,
                                              multicastGroupPort=4446, timeToLive=32"/>
                
          <cacheManagerPeerProviderFactory class=
                                    "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
                                    properties="peerDiscovery=manual,
                                    rmiUrls=//server1:40000/sampleCache1|//server2:40000/sampleCache1
                                    | //server1:40000/sampleCache2|//server2:40000/sampleCache2"/>     

          cacheManagerPeerListenerFactory:指定CacheManagerPeerListenerFactory,用于創(chuàng)建CacheManagerPeerListener,監(jiān)聽cluster中的復(fù)制信息
              屬性:
                  class:完整的工廠類名稱
                  properties:逗號(hào)分割的屬性

          默認(rèn)配置
           
              <cacheManagerPeerListenerFactory
                  class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
                  properties="hostName=fully_qualified_hostname_or_ip,
                              port=40001,
                              socketTimeoutMillis=120000"/>     

          defaultCache: 默認(rèn)緩存配置

              必須屬性:
                  name:設(shè)置緩存的名稱,用于標(biāo)志緩存,惟一
                  maxElementsInMemory:在內(nèi)存中最大的對(duì)象數(shù)量
                  maxElementsOnDisk:在DiskStore中的最大對(duì)象數(shù)量,如為0,則沒有限制
                  eternal:設(shè)置元素是否永久的,如果為永久,則timeout忽略
                  overflowToDisk:是否當(dāng)memory中的數(shù)量達(dá)到限制后,保存到Disk

              可選的屬性:
                  timeToIdleSeconds:設(shè)置元素過(guò)期前的空閑時(shí)間
                  timeToLiveSeconds:設(shè)置元素過(guò)期前的活動(dòng)時(shí)間
                  diskPersistent:是否disk store在虛擬機(jī)啟動(dòng)時(shí)持久化。默認(rèn)為false
                  diskExpiryThreadIntervalSeconds:運(yùn)行disk終結(jié)線程的時(shí)間,默認(rèn)為120秒
                  memoryStoreEvictionPolicy:策略關(guān)于Eviction

          緩存子元素:
             
              cacheEventListenerFactory:注冊(cè)相應(yīng)的的緩存監(jiān)聽類,用于處理緩存事件,如put,remove,update,和expire
              bootstrapCacheLoaderFactory:指定相應(yīng)的BootstrapCacheLoader,用于在初始化緩存,以及自動(dòng)設(shè)置。
          如下的例子:
           
           <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
                   properties="replicateAsynchronously=true,
                   replicatePuts=true,
                   replicateUpdates=true,
                   replicateUpdatesViaCopy=true,
                   replicateRemovals=true "/>     
           
          <bootstrapCacheLoaderFactory
                  class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"
                  properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"/>     
           
           <defaultCache
                      maxElementsInMemory="10000"
                      eternal="false"
                      timeToIdleSeconds="120"
                      timeToLiveSeconds="120"
                      overflowToDisk="true"
                      maxElementsOnDisk="10000000"
                      diskPersistent="false"
                      diskExpiryThreadIntervalSeconds="120"
                      memoryStoreEvictionPolicy="LRU"
                      />     

          cache配置同defaultCache
           
          <cache name="sampleDistributedCache1"
                     maxElementsInMemory="10"
                     eternal="false"
                     timeToIdleSeconds="100"
                     timeToLiveSeconds="100"
                     overflowToDisk="false">
                  <cacheEventListenerFactory
                          class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/>
                  <bootstrapCacheLoaderFactory
                          class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"/>
              </cache>     

          基本上都比較簡(jiǎn)單,當(dāng)然也可以直接使用程序?qū)崿F(xiàn)相應(yīng)的功能
          posted on 2007-04-05 18:42 布衣郎 閱讀(7073) 評(píng)論(1)  編輯  收藏 所屬分類: jdk相關(guān)

          FeedBack:
          # re: 關(guān)于ehcache 配置
          2009-04-30 15:36 | josdoc
          Java開源文檔(www.josdoc.com)轉(zhuǎn)載了您的文章,若不同意請(qǐng)告知,謝謝!  回復(fù)  更多評(píng)論
            

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿(12)

          隨筆分類(59)

          隨筆檔案(57)

          blog

          java

          uml

          搜索

          •  

          積分與排名

          • 積分 - 357318
          • 排名 - 155

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 汾西县| 昭平县| 莲花县| 民乐县| 峨眉山市| 如皋市| 彝良县| 裕民县| 西乌| 义乌市| 星子县| 桓台县| 临邑县| 冀州市| 丹凤县| 乐至县| 云安县| 嘉荫县| 南涧| 新宁县| 木兰县| 华坪县| 富阳市| 务川| 宝清县| 普宁市| 大同县| 长葛市| 始兴县| 花莲市| 乌鲁木齐县| 镇巴县| 旬阳县| 白银市| 土默特左旗| 岳西县| 海宁市| 佛教| 赤水市| 安义县| 许昌市|