简要说一下当前的场景。
项目有网站端和app端,由于网站端和app端连接的是同一个数据库,故在持久化层上,数据是一致的。由于项目开发处于初期,故没有将网站端和 app 端分开部署,而是部署到同一台服务器上。
由于引入 ehcache,所以在同台物理机上的 ehcache 的缓存无法同步。
如下为两个项目共用的ehcache rmi 配置
<?xml version="1.0" encoding="UTF-8"?>
<ehcache updateCheck="false" name="defaultCache">
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,multicastGroupPort=4446, timeToLive=32"/>
<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="port=40001"/>
<diskStore path="java.io.tmpdir/otc"/>
<!-- 默认缓存配置. -->
<defaultCache maxEntriesLocalHeap="100" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600"
overflowToDisk="true" maxEntriesLocalDisk="100000">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,
replicateUpdatesViaCopy=false, replicateRemovals=true,asynchronousReplicationIntervalMillis=1000"/>
<bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"/>
</defaultCache>
<!-- 系统缓存 -->
<cache name="sysCache" maxEntriesLocalHeap="2000" timeToIdleSeconds="0" timeToLiveSeconds="86400"
overflowToDisk="true">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,
replicateUpdatesViaCopy=false, replicateRemovals=true,asynchronousReplicationIntervalMillis=1000"/>
<bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"/>
</cache>
</ehcache>
该如何进行配置?
找到一些类似的问题 单机上多个ehcache实例,如何配置? http://stackoverflow.com/questions/8484745/running-multiple-instances-of-ehcache-on-the-same-machine-with-a-single-config
两个java程序能否共享同一个 ehcache 对象 http://stackoverflow.com/questions/17162649/is-it-possible-to-access-the-same-ehcache-object-from-two-different-java-applica
其中一个回答给出了如下配置:
<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" properties="" />
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。