ehcache集群缓存不同步问题

sunnyjava 发布于 2012/06/11 14:18
阅读 15K+
收藏 6

使用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如何实现集群啊?

以下是问题补充:

@技术古玩:具体点说下你怎么解决的啊?我好急,解决不了。谢谢 (2013/07/04 21:03)
加载中
0
s
sunnyjava

谢谢,已结贴,哎,网上的文章前篇一律,还是官网权威啊。

按这个配置,一下子就搞定了,http://ehcache.org/documentation/replication/rmi-replicated-caching,这年头还是官网可靠啊!

1
NoahX
NoahX

好像是少配置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>

0
龍神
龍神
不会,,,帮顶
0
红薯
红薯

如果配置无误,无法同步是不可能的,稍微慢1-2秒倒是有可能

请参考 http://www.oschina.net/question/12_7773

0
s
sunnyjava
配置我已经贴出来了,确实无法同步,请问到底是什么问题呢?
0
dedenj
dedenj
被墙了没?
0
技术古玩
技术古玩
最后怎么解决的??求助啊,我也是这个问题
0
技术古玩
技术古玩
能详细点吗??
0
小翔
小翔

可以不用去读配置xml生成cache吧。用数据库时间去生成和更新cache数据也是可行的

0
技术古玩
技术古玩

和官网一模一样配置就成功了,,spring3.1 基于注解的RMI分布式ehcache

诸位可以试试http://ehcache.org/documentation/replication/rmi-replicated-caching

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部