开发者社区> 问答> 正文

单机 ehcache 的缓存同步

已解决

简要说一下当前的场景。

项目有网站端和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>

该如何进行配置?

展开
收起
qyvlik 2017-05-11 20:45:11 4486 0
1 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
基于英特尔 SSD 的虚拟机缓存解决SSD 立即下载
用户态高速块缓存方案 立即下载
高性能Web架构之缓存体系 立即下载