特定 Spring 配置中的缓存重复

Cache duplication in specific Spring configuration

我在集群中有两个 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

非常感谢

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

<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>