在特定的Spring配置中缓存重复

问题描述 投票:0回答:1

我在群集中有两个tomcat服务器,我想复制群集中的缓存(每个服务器中的缓存相同)。如何使用以下配置使用Ehcache和JGroups / RMI执行此操作(无需定义缓存):

1.Context配置:

<bean id="myEhCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="classpath:my-ehcache.xml"/>
</bean>

2.Controller:

@Controller 
public class MyUniqueService {

    @Resource(name="myEhCacheManager")
    private CacheManager cacheManager;

    ...
}

这里提到了这个配置:Getting an EhCache instance with Spring... intelligently

非常感谢

spring caching ehcache
1个回答
0
投票

要在其他服务器上复制缓存,配置可以如下所示:

<ehcache>
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
                                 properties="peerDiscovery=manual, rmiUrls=${other sharinr server cache url}"/>
<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
                                 properties="hostName=localhost,port=xxx, remoteObjectPort=xxx, socketTimeoutMillis=2000"/>


 <cache name="MY_CACHE"
     maxEntriesLocalHeap=""
     eternal="false"
     timeToIdleSeconds=""
     timeToLiveSeconds=""
     maxEntriesLocalDisk=""
     diskExpiryThreadIntervalSeconds=""
     memoryStoreEvictionPolicy="LRU">

 <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
                             properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,
          replicateUpdatesViaCopy=false, replicateRemovals=true "/>
</cache>
</ehcache>
© www.soinside.com 2019 - 2024. All rights reserved.