簡體   English   中英

在Tomcat群集中使用ehcache進行緩存復制

[英]Cache repliation with ehcache in Tomcat cluster

我為3個不同的tomcat實例使用以下ehcache配置。

我的假設是,在每個ehcache中,我們都應將所有其他節點定義為提供者,並將當前節點定義為偵聽器。

是否應該在每個ehcache.xml中定義所有緩存? 如果是,是否還要將這些名稱添加到RMI地址中? 我這樣定義了ehcache。 其中兩個緩存的復制工作正常,但其他兩個緩存的復制則不起作用(activityCache和classificationCache)。 當然,它應該取決於它們的實現,但是在此時,我想確保ehcache配置正確。

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="ehcache.xsd">

 <cache name="activityCache"
           maxElementsInMemory="30"
           maxElementsOnDisk="100000"
           eternal="true"
           overflowToDisk="true"
           diskPersistent="true"
           diskSpoolBufferSizeMB="20"
           timeToIdleSeconds="50"
           timeToLiveSeconds="5"
           memoryStoreEvictionPolicy="LFU">

            <bootstrapCacheLoaderFactory class = "net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" properties = "bootstrapAsynchronously=false, maximumChunkSizeBytes=5000000"/>

            <cacheEventListenerFactory class = "net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, asynchronousReplicationIntervalMillis=100"/>

           </cache>

         <cache name="featureCache"
           maxElementsInMemory="30"
           maxElementsOnDisk="100000"
           eternal="true"
           overflowToDisk="true"
           diskPersistent="true"
           diskSpoolBufferSizeMB="20"
           timeToIdleSeconds="50"
           timeToLiveSeconds="5"
           memoryStoreEvictionPolicy="LFU">            

            <bootstrapCacheLoaderFactory class = "net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" properties = "bootstrapAsynchronously=false, maximumChunkSizeBytes=5000000"/>

            <cacheEventListenerFactory class = "net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, asynchronousReplicationIntervalMillis=100"/>

           </cache> 

        <cache name="classificationCache"
           maxElementsInMemory="30"
           maxElementsOnDisk="100000"
           eternal="true"
           overflowToDisk="true"
           diskPersistent="true"
           diskSpoolBufferSizeMB="20"
           timeToIdleSeconds="50"
           timeToLiveSeconds="5"
           memoryStoreEvictionPolicy="LFU">    

            <bootstrapCacheLoaderFactory class = "net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" properties = "bootstrapAsynchronously=false, maximumChunkSizeBytes=5000000"/>

            <cacheEventListenerFactory class = "net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, asynchronousReplicationIntervalMillis=100"/>

           </cache>

    <cache name="userGroupCache"
           maxElementsInMemory="30"
           maxElementsOnDisk="100000"
           eternal="true"
           overflowToDisk="true"
           diskPersistent="true"
           diskSpoolBufferSizeMB="20"
           timeToIdleSeconds="50"
           timeToLiveSeconds="5"
           memoryStoreEvictionPolicy="LFU">

            <bootstrapCacheLoaderFactory class = "net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" properties = "bootstrapAsynchronously=false, maximumChunkSizeBytes=5000000"/>

            <cacheEventListenerFactory class = "net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, asynchronousReplicationIntervalMillis=100"/>

           </cache>                

 <cacheManagerPeerProviderFactory class = "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" properties = "peerDiscovery=manual, rmiUrls=//localhost:40002/activityCache|//localhost:40002/userGroupCache|//localhost:40002/featureCache|//localhost:40002/classificationCache//localhost:40003/activityCache|//localhost:40003/userGroupCache|//localhost:40003/featureCache|//localhost:40003/classificationCache"/>

<cacheManagerPeerListenerFactory class = "net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" properties = "hostName=localhost, port=40001, socketTimeoutMillis=2000"/>

</ehcache>

這也是緩存和cahchSevices的定義:

     <bean id="featureCache" parent="abstractOptionalCache">
        <property name="maxElementsInMemory" value="${cache.feature.maxMemoryElements}"/>
        <property name="maxElementsOnDisk" value="${cache.feature.maxDiskElements}"/> 
        <property name="overflowToDisk" value="${cache.feature.useDisk}"/>
      </bean>

      <bean id="featureCacheService" parent="abstractService" class="com.service.business.cache.impl.ehcache.EHcacheFeatureCacheService">
        <property name="cache"  ref="featureCache"/>
        <property name="enabled" value="${cache.feature.enable}"/>
      </bean> 

      <bean id="activityCache" parent="abstractMandatoryCache">
        <property name="cacheManager" ref="cacheManager"/>
        <property name="maxElementsInMemory" value="${cache.activity.maxMemoryElements}"/>
      </bean>

       <bean id="activityCacheService" parent="abstractService" class="com.service.business.cache.impl.ehcache.EHcacheActivityCacheService">
        <property name="cache"  ref="activityCache"/>
      </bean> 

      <bean id="classificationCache" parent="abstractOptionalCache">
        <property name="cacheManager" ref="cacheManager"/>
        <property name="maxElementsInMemory" value="${cache.classification.maxMemoryElements}"/>
        <property name="maxElementsOnDisk" value="${cache.classification.maxDiskElements}"/> 
        <property name="overflowToDisk" value="${cache.classification.useDisk}"/>
      </bean>

      <bean id="classificationCacheService" parent="abstractService" class="com.service.business.cache.impl.ehcache.EHcacheClassificationCacheService">
        <property name="cache"     ref="classificationCache" />
        <property name="enabled" value="${cache.classification.enable}"/>
      </bean>

        <bean id="userGroupCache" parent="abstractOptionalCache">
    <property name="cacheManager" ref="cacheManager"/>
    <property name="maxElementsInMemory" value="${cache.userGroup.maxMemoryElements}"/>
    <property name="maxElementsOnDisk" value="${cache.userGroup.maxDiskElements}"/> 
    <property name="overflowToDisk" value="${cache.userGroup.useDisk}"/>
  </bean>

  <bean id="userGroupCacheService" parent="abstractService" class="com.service.business.cache.impl.ehcache.EHcacheUserGroupCacheService">
    <property name="cache"     ref="userGroupCache" />
    <property name="enabled" value="${cache.userGroup.enable}"/>
  </bean> 

我將根據您的要求提供更多信息。

先感謝您。

你做對了,但是在做錯了

rmiUrls=//localhost:40002/activityCache|//localhost:40002/userGroupCache|//localhost:40002/featureCache|//localhost:40002/classificationCache//localhost:40003/activityCache|//localhost:40003/userGroupCache|//localhost:40003/featureCache|//localhost:40003/classificationCache

你錯過| 在分類和活動緩存之間

//localhost:40002/classificationCache//localhost:40003/activityCache

這就是這兩個緩存都不起作用的原因!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM