2016年03月24日   码农之路   8,304 次浏览

ehcache有几种方式实现集群:rmi、jgroup、jms,这里讲一下ehcache使用rmi的实现方式。
主要有三个配置:
1、cacheManagerPeerProviderFactory配置:
   <cacheManagerPeerProviderFactory
        class= “net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory”
        properties= “peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446, timeToLive=1”/>
timeToLive的值指的是数据包可以传递的域或是范围。约定如下:
0是限制在同一个服务器
1是限制在同一个子网(默认)
32是限制在同一个网站
64是限制在同一个region
128是限制在同一个大洲
255是不限制

2、cacheManagerPeerListenerFactory配置: 
   <cacheManagerPeerListenerFactory
        class= “net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory”
        properties= “hostName=192.168.1.101, port=40001, socketTimeoutMillis=2000”/>
hostName说明:为本机IP,不指定时hostname将使用InetAddress.getLocalHost().getHostAddress()来得到。当在同一台机器上有多个CacheManager的时候,应该用localhost来配置。
3、cacheEventListenerFactory配置:
     <cacheEventListenerFactory
        class= “net.sf.ehcache.distribution.RMICacheReplicatorFactory”
        properties= “replicateAsynchronously=true,
             replicatePuts=true,
             replicateUpdates=true,
             replicateUpdatesViaCopy=true,
             replicateRemovals=true” />
可以使用默认配置:
<cacheEventListenerFactory class=”net.sf.ehcache.distribution.RMICacheReplicatorFactory”/>
参数说明:
replicateAsynchronously=true | false – 复制方式是异步的(指定为true时)还是同步的(指定为false时)。默认是true。
replicatePuts=true | false – 当一个新元素增加到缓存中的时候是否要复制到其他的peers。默认是true。
replicateUpdates=true | false – 当一个已经在缓存中存在的元素被覆盖时是否要进行复制。默认是true。
replicateUpdatesViaCopy=true | false – 当一个元素被拷贝到其他的cache中时是否进行复制(指定为true时为复制)。默认是true。
replicateRemovals= true | false – 当元素移除的时候是否进行复制。默认是true。
附上实例:
<?xml version=“1.0” encoding= “UTF-8”?>
<ehcache xmlns:xsi= “http://www.w3.org/2001/XMLSchema-instance”
         xsi:noNamespaceSchemaLocation=“http://ehcache.org/ehcache.xsd”
         updateCheck= “false” monitoring =“autodetect” dynamicConfig=“true” >
      <diskStore path =“java.io.tmpdir/ehcache” />
 
    <cacheManagerPeerProviderFactory
        class= “net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory”
        properties= “peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446, timeToLive=1”/>
       
    <cacheManagerPeerListenerFactory
        class= “net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory”
        properties= “port=40001, socketTimeoutMillis=2000”/>
 
    <cache name =“sessionCache”
           maxElementsInMemory= “10000”
           eternal= “false”
           overflowToDisk= “true”
           timeToIdleSeconds= “3600”
           memoryStoreEvictionPolicy= “LFU”>
           <cacheEventListenerFactory
               class= “net.sf.ehcache.distribution.RMICacheReplicatorFactory”
                    properties= “replicateAsynchronously=true,
                    replicatePuts=true,
                    replicateUpdates=true,
                    replicateUpdatesViaCopy=true,
                    replicateRemovals=true” />
    </cache >
</ehcache>
赞 赏
申明:除非注明,本站文章均为原创,转载请以链接形式标明本文地址。 如有问题,请于一周内与本站联系,本站将在第一时间对相关内容进行处理。
本文地址: http://www.yyjjssnn.cn/articles/715.html

>>> Hello World <<<

这篇内容是否帮助到你了呢?

如果你有任何疑问或有建议留给其他朋友,都可以给我留言。

目前有4条留言:

  • 1# haha:
    2024-08-13 16:22

    :smile3: :smile3: :smile36: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile37: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile36: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile24: :smile10: :smile10: :smile10: :smile10: :smile10: :smile10: :smile12: :smile12: :smile12: :smile12: :smile12: :smile12: :smile12: :smile12: :smile12: :smile12: :smile12: :smile12: :smile12: :smile12: :smile12: :smile13: :smile13: :smile13: :smile13: :smile13: :smile13: :smile13: :smile13:

  • 2# 23:
    2024-08-13 15:34

    :smile3: :smile3: :smile3: :smile3: :smile14: :smile32: :smile32: :smile52: :smile55: :smile55: :smile7:

  • 3# 文刀木易:
    2019-11-08 17:03

    :simple-smile: :rolleyes: :frownie:

  • 4# 匿名:
    2017-08-03 08:55

    :smile56: :smile32: :smile30: :smile27: :smile25: :smile20: :smile1: :smile22: :smile25:

:wink: :twisted: :surprised: :smile: :smile9: :smile8: :smile7: :smile6: :smile5: :smile56: :smile55: :smile54: :smile53: :smile52: :smile51: :smile50: :smile4: :smile49: :smile48: :smile47: :smile46: :smile45: :smile44: :smile43: :smile42: :smile41: :smile40: :smile3: :smile39: :smile38: :smile37: :smile36: :smile35: :smile34: :smile33: :smile32: :smile31: :smile30: :smile2: :smile29: :smile28: :smile27: :smile26: :smile25: :smile24: :smile23: :smile22: :smile21: :smile20: :smile1: :smile19: :smile18: :smile17: :smile16: :smile15: :smile14: :smile13: :smile12: :smile11: :smile10: :smile0: :sad: :rolleyes1: :redface: :razz: :question: :neutral: :mrgreen: :mad: :lol: :idea: :exclaim: :evil: :eek: :cry: :cool: :confused: :biggrin: :arrow:

友情链接: 程序员刘杨 刘杨
Copyright 2003~2018 保留所有权利 | 网站地图
备案号:湘ICP备14001005号-2

湘公网安备 43011102001322号