记录问题1:分布式采用了rmi配置,但是配置后一直没有作用,控制台报以下警告:
[WARN] 10:19:59 [main CacheManager:292] -
The source of the configuration was classpath.
The diskStore path for this CacheManager will be set to C:\apache-tomcat-5.5.16\temp\ehcache_auto_created_1168453199935.
To avoid this warning consider using the CacheManager factory methods to create a singleton CacheManager or specifying a
separate ehcache configuration (ehcache.xml) for each CacheManager instance.>
[WARN] 10:19:59 [main CacheManager:319] -
The resource is RMI listener port: 40001.
Attempting automatic resolution. The source of the configuration was classpath.
To avoid this warning consider using the CacheManager factory methods to create a singleton CacheManager or specifying a
separate ehcache configuration (ehcache.xml) for each CacheManager instance.>
Station [WARN] 10:19:59 [main RMICacheManagerPeerListener:145] -
解决办法:在spring中ehcache配置中需要增加属性:property name="shared" value="true"
完成配置如下:
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml" />
<property name="shared" value="true"/>
</bean>
记录问题二:ehcache.xml配置信息如下所示:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd">
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,
rmiUrls=//10.4.7.194:40001/CodeCache|//10.4.7.194:40001/UsersDataCache" />
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=10.4.7.193,port=40001, socketTimeoutMillis=2000"/>
<cache name="CodeCache"
maxElementsInMemory="10000"
eternal="false"
overflowToDisk="true"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU"
>
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=true,
replicatePuts=true,
replicateUpdates=true,
replicateUpdatesViaCopy=true,
replicateRemovals=true"/>
<bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"/>
</cache>
<cache name="UsersDataCache"
maxElementsInMemory="20000"
eternal="false"
overflowToDisk="true"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU"
>
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=true,
replicatePuts=true,
replicateUpdates=true,
replicateUpdatesViaCopy=true,
replicateRemovals=true"/>
<bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"/>
</cache>
</ehcache>