在一个JVM里实现ehcache replciation分布式缓存

 

ehcache是一个开源的Java本地缓存框架,同时以replication的形式提供分布式缓存管理。这里介绍下使用RMI手动配置的方法在一个JVM里面启动多个CacheManager来实现分布式缓存。

 

这里配置3个CacheManager,由于只有一台机器,所以实在一个JVM里面使用3个CacheManager的方法来模拟分布式。

 

 

 

<?xml version="1.0" encoding="UTF-8"?>

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
	monitoring="autodetect" dynamicConfig="true" name="nodeA">

	<cacheManagerPeerProviderFactory
		class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
		properties="peerDiscovery=manual,
					rmiUrls=//localhost:40002/cache1|//localhost:40003/cache1" />

	<cacheManagerPeerListenerFactory
		class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
		properties="hostName=localhost, port=40001,
					socketTimeoutMillis=2000" />

	<cache name="cache1" maxEntriesLocalHeap="10" eternal="false"
		timeToIdleSeconds="100" timeToLiveSeconds="100" overflowToDisk="false">
		<cacheEventListenerFactory
			class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
			properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,
						replicateUpdatesViaCopy=false, replicateRemovals=true " />
	</cache>

</ehcache>

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值