配置EhCache缓存集群,有A,B服务器,同时启动服务器,A服务器缓存可以同步到B服务器,而B服务器换成不能同步到A服务器:下面是xml
A服务器:
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446, timeToLive=32"/>
<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" properties="hostName=10.10.7.231, port=40001,socketTimeoutMillis=2000" />
<defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" diskSpoolBufferSizeMB="30" maxElementsOnDisk="10000000"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU">
</defaultCache>
<!-- Special objects setting. -->
<cache name="com.dsideal.modules.sys.entity.Dict" maxEntriesLocalHeap="1000" eternal="false" overflowToDisk="true" maxEntriesLocalDisk="100000" memoryStoreEvictionPolicy="LFU"
transactionalMode="off">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" />
</cache>
B服务器:
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446, timeToLive=32"/>
<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" properties="hostName=10.10.7.103, port=40001,socketTimeoutMillis=2000" />
<defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" diskSpoolBufferSizeMB="30" maxElementsOnDisk="10000000"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU">
</defaultCache>
<!-- Special objects setting. -->
<cache name="com.dsideal.modules.sys.entity.Dict" maxEntriesLocalHeap="1000" eternal="false" overflowToDisk="true" maxEntriesLocalDisk="100000" memoryStoreEvictionPolicy="LFU"
transactionalMode="off">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" />
</cache>
https://www.ibm.com/developerworks/cn/java/j-lo-ehcache/
Ehcache 有几种集群的方案,包括 RMI 和 JGroups。我的这篇文章里都有详细介绍哦:)