【问题标题】:Cache duplication in specific Spring configuration特定 Spring 配置中的缓存重复
【发布时间】:2017-04-11 23:56:17
【问题描述】:

我在集群中有两台 tomcat 服务器,我想复制集群中的缓存(每台服务器中的缓存相同)。我如何使用以下配置(不定义缓存)使用 Ehcache 和 JGroups/RMI 做到这一点:

1.上下文配置:

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

2.控制器:

@Controller 
public class MyUniqueService {

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

    ...
}

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

非常感谢

【问题讨论】:

  • 重复缓存到底是什么意思?
  • 是保存缓存数据还是保存缓存到其他缓存=
  • 谢谢,我有一个有两个 AS 的集群,我希望每个服务器都有相同的缓存

标签: spring caching ehcache


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2018-07-31
    • 2012-10-22
    • 1970-01-01
    • 2015-04-02
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    • 2020-08-31
    • 1970-01-01
    相关资源
    最近更新 更多