单机 ehcache 的缓存同步-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

单机 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 4294 0
1 条回答
写回答
取消 提交回答
问答排行榜
最热
最新
相关电子书
更多
分布式高并发缓存6.0
立即下载
高并发分布式缓存Redis6.0
立即下载
基于英特尔 SSD 的虚拟机缓存解决SSD
立即下载