[英]Ehcache not replicating between two tomcat on the same machine
我正在嘗試在同一台計算機上的兩個tomcat之間設置緩存復制。 緩存工作正常,但復制無效。
為了進行測試,我在服務器1上調用了count方法。然后在服務器2上添加了一個實體,並在服務器2上調用了count方法。最后,我在服務器1上再次調用了count方法:緩存被命中,我添加的實體找不到。
Tomcat版本:6,Java版本:1.6,Ehcache版本:1.3,OS:Linux
啟動時登錄(兩台服務器相同):
DEBUG net.sf.ehcache.store.MemoryStore - Initialized net.sf.ehcache.store.LruMemoryStore for myCacheSample
DEBUG net.sf.ehcache.store.LruMemoryStore - myCacheSample Cache: Using SpoolingLinkedHashMap implementation
DEBUG net.sf.ehcache.Cache - Initialised cache: myCacheSample
DEBUG net.sf.ehcache.distribution.RMICacheManagerPeerListener - Adding myCacheSample to RMI listener
DEBUG net.sf.ehcache.distribution.RMICacheManagerPeerListener - 0 RMICachePeers bound in registry for RMI listener
代碼添加:
public void persist(MyEntity myEntity) {
getEntityManager().persist(myEntity);
}
具有緩存設置的代碼數:
public int count(String criteriaStr) {
Criteria criteria = ((HibernateEntityManager) getEntityManager()).getSession().createCriteria(MyEntity.class);
criteria.setCacheable(true).setCacheRegion("myCacheSample");
criteria.add(Restrictions.eq("criteriaStr", criteriaStr));
return (Integer) criteria.setProjection(Projections.rowCount()).uniqueResult();
}
刪除代碼:
public void remove(MyEntity myEntity) {
getEntityManager().remove(myEntity);
getEntityManager().flush();
}
服務器1 ehcache.xml(對於服務器2:端口40001和40002已切換):
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,
rmiUrls=//localhost:40002/myCacheSample"/>
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="
hostName=localhost,
port=40001,
socketTimeoutMillis=2000
"/>
<defaultCache
diskExpiryThreadIntervalSeconds="120"
diskPersistent="false"
eternal="false"
maxElementsInMemory="1000"
memoryStoreEvictionPolicy="LRU"
overflowToDisk="true"
timeToIdleSeconds="120"
timeToLiveSeconds="120">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="
asynchronousReplicationIntervalMillis=1000,
replicateAsynchronously=true,
replicatePuts=false,
replicateRemovals=true,
replicateUpdates=true,
replicateUpdatesViaCopy=false
"/>
<cache
eternal="false"
maxElementsInMemory="1000"
timeToLiveSeconds="300"
timeToIdleSeconds="300"
name="myCacheSample"
overflowToDisk="false"/>
謝謝您的解答!
3個tomcat實例的RMI復制的有效配置希望它對您有用。
Server 1
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual, rmiUrls=//localhost:40002/apicache|//localhost:40003/apicache" />
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=192.168.1.152, port=40001, socketTimeoutMillis=2000" />
Server 2
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual, rmiUrls=//localhost:40001/apicache|//localhost:40003/apicache" />
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=192.168.1.152, port=40002, socketTimeoutMillis=2000" />
Server 3
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual, rmiUrls=//localhost:40001/apicache|//localhost:40002/apicache" />
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=192.168.1.152, port=40003, socketTimeoutMillis=2000" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.