Ehcache集群

Ehcache集群的两种方式:组播方式和点对点方式

一、   组播方式

1)    配置cacheManagerPeerProviderFactory

<cacheManagerPeerProviderFactory

class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"

properties="peerDiscovery=automatic,multicastGroupAddress=230.0.0.2,multicast      groupPort=4447,timeToLive=1”

propertySeparator=","                          

              />

            作用:当缓存发生变化,进行广播

            属性: peerDiscovery:atutomatic为自动;

multicastGroupAddress:广播组地址,指定D类IP地址空间,范围从 224.0.1.0 到 238.255.255.255 中的任何一个地址

                     mulicastGroupPort广播组端口

                     timeToLive:搜索范围

0是同一台服务器

1是同一个子网

32是指同一站点

64是指同一块地域

128是同一块大陆

256是任何

 

 

2)    配置cacheManagerPeerListenerFactory

<cacheManagerPeerListenerFactory

       class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"

              />

            作用:监听本服务器所有端口

二、   点对点方式

1)    配置cacheManagerPeerProviderFactory

<cacheManagerPeerProviderFactory

       class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"

properties="peerDiscovery=manual,rmiUrls=//192.168.4.50:40002/com.pccw.kernel.dic.vo.ArchDicKindVOImpl|//192.168.4.50:40002/com.pccw.kernel.dic.vo.ArchDicItemVOImpl"

/>

作用:当缓存发生变化,通知集群中其他节点。

属性: peerDiscovery:manual为手动

      rmiUrls:通知需要同步的缓存

3)    配置cacheManagerPeerListenerFactory

<cacheManagerPeerListenerFactory

       class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"

properties="hostName=192.168.4.24,port=40001,socketTimeoutMillis=2000"

              />

              作用:监听本服务器指定端口

 

 缓存的配置(共同部分)

 

cacheEventListenerFactory:注册相应的的缓存监听类,用于处理缓存事件,如put,remove,update,和expire
bootstrapCacheLoaderFactory:指定相应的BootstrapCacheLoader,用于  在初始化缓存(从硬盘读取,overflowToDisk为false时,此配置失效),以及自动设置。
 
p2p方式
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd">


	<!--
	Caches in this file can be clustered and are configured to be clustered.
	-->


	<diskStore path="java.io.tmpdir/arch" />
	<cacheManagerEventListenerFactory class="" properties="" />
	<cacheManagerPeerProviderFactory
		class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
		properties="peerDiscovery=manual,rmiUrls=//192.168.4.24:40001/com.pccw.kernel.dic.vo.ArchDicKindVOImpl|//192.168.4.24:40001/com.pccw.kernel.dic.vo.ArchDicItemVOImpl"
	/>
	<cacheManagerPeerListenerFactory
		class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
		properties="hostName=192.168.0.50,port=40002,socketTimeoutMillis=2000"/
	/>
	<defaultCache
		maxElementsInMemory="10000"
		eternal="false"
        timeToIdleSeconds="600"
		overflowToDisk="false"
	>
        <cacheEventListenerFactory
			class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
			properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true"
			propertySeparator=","
		/>
		<bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
	</defaultCache>
	<cache
		name="sessionCache"
		maxElementsInMemory="10000"
		eternal="true"
        timeToIdleSeconds="600"
		overflowToDisk="false"
	>
        <cacheEventListenerFactory
			class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
			properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true"
			propertySeparator=","
		/>
		<bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
	</cache>
	
	<cache
		name="customCache"
		maxElementsInMemory="10000"
		eternal="false"
        timeToIdleSeconds="600"
        timeToLiveSeconds="1800"
		overflowToDisk="false"
	>
        <cacheEventListenerFactory
			class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
			properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true"
			propertySeparator=","
		/>
		<bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
	</cache>
	
	<cache 
		name="com.pccw.kernel.dic.vo.ArchDicItemVOImpl"
		maxElementsInMemory="100000"
           eternal="true"
           timeToIdleSeconds="1200"
           timeToLiveSeconds="1200"
           overflowToDisk="false"
	>
        <cacheEventListenerFactory
			class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
			properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true"
			propertySeparator=","
		/>
		<bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
	</cache>
		
	<cache 
		name="com.pccw.kernel.dic.vo.ArchDicKindVOImpl"
		maxElementsInMemory="100000"
           eternal="true"
           timeToIdleSeconds="1200"
           timeToLiveSeconds="1200"
           overflowToDisk="false"      
	>
        <cacheEventListenerFactory
			class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
			properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true"
			propertySeparator=","
		/>
		<bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
	</cache>
</ehcache>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值