开发者社区> 问答> 正文

ehcache集群缓存不同步问题

使用EhCache2.52,做缓存,缓存用的Spring3.1注解,测试用两台服务器集群EhCache,出现缓存不同步问题,访问两台服务器都各自缓存了,A服务器缓存更新,访问B服务器依旧是旧的缓存数据,数据没更新。

A服务器ehcache.xml中缓存配置如下:

<cacheManagerPeerProviderFactory     

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

     properties="hostName=192.168.3.111,    

     port=4567,    

     socketTimeoutMillis=2000,    

     peerDiscovery=manual,    

     rmiUrls=//192.168.3.211:4567/param"

 />

<cache

 name="param"

 maxElementsInMemory="10000"

 maxElementsOnDisk="10000000"

 eternal="true"

 overflowToDisk="true"

 diskPersistent="true"

 memoryStoreEvictionPolicy="LFU">

 <cacheEventListenerFactory

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

         properties="replicateAsynchronously=true,

     replicatePuts=true,

     replicateUpdates=true, 

         replicateUpdatesViaCopy=false,  

     replicateRemovals=true"/>

</cache>

B服务器ehcache.xml中缓存配置如下:

<cacheManagerPeerProviderFactory     

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

     properties="hostName=192.168.3.211,    

     port=4567,    

     socketTimeoutMillis=2000,    

     peerDiscovery=manual,    

     rmiUrls=//192.168.3.111:4567/param"

 />

<cache

 name="param"

 maxElementsInMemory="10000"

 maxElementsOnDisk="10000000"

 eternal="true"

 overflowToDisk="true"

 diskPersistent="true"

 memoryStoreEvictionPolicy="LFU">

 <cacheEventListenerFactory

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

         properties="replicateAsynchronously=true,

     replicatePuts=true,

     replicateUpdates=true, 

         replicateUpdatesViaCopy=false,  

     replicateRemovals=true"/>

</cache>

也曾尝试使用自动发现

<cacheManagerPeerProviderFactory    

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

     properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,    

     multicastGroupPort=4446, timeToLive=32"    

 />

以及jsGroups,都无法同步缓存,其中jsGroup最新版的还不能和EhCache2.5.2组合使用,只能用2.X,而且缓存的DAO方法参数中有对象实现了序列化,ehcache-jgroupsreplication还会报错,请问这是何解啊?EhCache如何实现集群啊?

展开
收起
a123456678 2016-03-16 14:21:10 4614 0
1 条回答
写回答
取消 提交回答
  • 好像是少配置bootstrapCacheLoaderFactory,启动时导致初始数据的不同步

    以下是我的配置

    <ehcache xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" monitoring="autodetect" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <diskStore path="java.io.tmpdir"/>
    <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.14, multicastGroupPort=4446, timeToLive=1"/>
    <cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"/>
    <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" maxElementsOnDisk="10000000" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU"/>
    <cache name="clusterCache" maxElementsInMemory="100" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="false" diskPersistent="false">
    <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true,replicatePuts=true,replicateUpdates=true,replicateUpdatesViaCopy=true,replicateRemovals=true"/>
    <bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"/>
    </cache>
    </ehcache>
    2019-07-17 19:03:58
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
基于英特尔 SSD 的虚拟机缓存解决SSD 立即下载
用户态高速块缓存方案 立即下载
高性能Web架构之缓存体系 立即下载