閑人野居
          好好學習,天天向上
          posts - 57,  comments - 137,  trackbacks - 0
          欠了很久的文章,本來都不想發了,可還是發吧

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

          配置元素說明:

          diskStore:配置DiskStore,當需要使用磁盤保存的時候,需要對象實現序列化接口

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

          cacheManagerEventListenerFactory :指定CacheManagerEventListenerFactory,用于創建CacheManagerPeerProvider

          用于提醒當CacheManager中的緩存增加或者刪除時。
             
              屬性:class:完整的工廠類名稱
                   properties:逗號分割的屬性

          事件包括 增加cache和刪除cache

          cacheManagerPeerProviderFactory:指定CacheManagerPeerProviderFactory,用于創建CacheManagerPeerProvider,用于在cluster中查找CacheManagers,主要用于機群環境

              屬性:
                  class:完整的工廠類名稱
                  properties:逗號分割的屬性

          默認的配置:
           
          <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,用于創建CacheManagerPeerListener,監聽cluster中的復制信息
              屬性:
                  class:完整的工廠類名稱
                  properties:逗號分割的屬性

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

          defaultCache: 默認緩存配置

              必須屬性:
                  name:設置緩存的名稱,用于標志緩存,惟一
                  maxElementsInMemory:在內存中最大的對象數量
                  maxElementsOnDisk:在DiskStore中的最大對象數量,如為0,則沒有限制
                  eternal:設置元素是否永久的,如果為永久,則timeout忽略
                  overflowToDisk:是否當memory中的數量達到限制后,保存到Disk

              可選的屬性:
                  timeToIdleSeconds:設置元素過期前的空閑時間
                  timeToLiveSeconds:設置元素過期前的活動時間
                  diskPersistent:是否disk store在虛擬機啟動時持久化。默認為false
                  diskExpiryThreadIntervalSeconds:運行disk終結線程的時間,默認為120秒
                  memoryStoreEvictionPolicy:策略關于Eviction

          緩存子元素:
             
              cacheEventListenerFactory:注冊相應的的緩存監聽類,用于處理緩存事件,如put,remove,update,和expire
              bootstrapCacheLoaderFactory:指定相應的BootstrapCacheLoader,用于在初始化緩存,以及自動設置。
          如下的例子:
           
           <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>     

          基本上都比較簡單,當然也可以直接使用程序實現相應的功能
          posted on 2007-04-05 18:42 布衣郎 閱讀(7073) 評論(1)  編輯  收藏 所屬分類: jdk相關

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

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

          常用鏈接

          留言簿(12)

          隨筆分類(59)

          隨筆檔案(57)

          blog

          java

          uml

          搜索

          •  

          積分與排名

          • 積分 - 357319
          • 排名 - 155

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 高淳县| 乐亭县| 平凉市| 陕西省| 宁国市| 麻城市| 荔波县| 武定县| 台湾省| 新巴尔虎右旗| 盐边县| 康定县| 封丘县| 吉安市| 星座| 大英县| 启东市| 临夏市| 依安县| 曲松县| 鄂尔多斯市| 淳化县| 惠安县| 合水县| 黑山县| 巩义市| 雅江县| 喀喇| 偏关县| 顺昌县| 鄱阳县| 阳信县| 南澳县| 宣恩县| 峨眉山市| 丰顺县| 大邑县| 龙海市| 双辽市| 玉门市| 沐川县|