ehcache集群缓存同步配置(rmi方式)实现session共享

`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 © www.yyjjssnn.cn`

转载于:https://my.oschina.net/maoguangdong/blog/1504382

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值