使用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如何实现集群啊?
谢谢,已结贴,哎,网上的文章前篇一律,还是官网权威啊。
按这个配置,一下子就搞定了,http://ehcache.org/documentation/replication/rmi-replicated-caching,这年头还是官网可靠啊!
好像是少配置bootstrapCacheLoaderFactory,启动时导致初始数据的不同步
以下是我的配置
如果配置无误,无法同步是不可能的,稍微慢1-2秒倒是有可能
请参考 http://www.oschina.net/question/12_7773
可以不用去读配置xml生成cache吧。用数据库时间去生成和更新cache数据也是可行的
和官网一模一样配置就成功了,,spring3.1 基于注解的RMI分布式ehcache
诸位可以试试http://ehcache.org/documentation/replication/rmi-replicated-caching。