<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<!--
cache配置:
对象在内存中的最大数量:
maxElementsInMemory:
因为内存是有限的,所以必须用maxElementsInMemory(必填项)设置每类对象在内存中的最大数量。
ehcache_failsafe.xml 中为10000。
到达内存中最大量时的过期/移出算法:
eternal:
如果为true,则永不过期,忽略后两个参数的设置。ehcache_failsafe.xml 为false.
timeToIdleSeconds:
以创建时间为基准开始计算的超时时长,默认为0,永不过时。ehcache_failsafe.xml 设为120秒。
timeToLiveSeconds:
在创建时间和最近访问时间中取出离现在最近的时间作为基准计算的超时时长,默认为0,永不过时。
ehcache_failsafe.xml 设为120秒。
如果timeToIdleSeconds和timeToLiveSeconds同时存在,则取出timeToIdleSeconds、timeToLiveSeconds最小的值,
即min(timeToIdleSeconds,timeToLiveSeconds),表示只要有一个超时成立即算超时。
移出算法:如果经过失效算法后,还是有很多有效的缓存,则执行清除算法。清除算法由两个参数组成:
memoryStoreEvictionPolicy: 默认为LRU(最近最少访问),另有先进先出(FIFO),最少访问次数(LFU)
overflowToDisk:为true,则将清除出来的缓存持久化到磁盘,否则人道毁灭之。
储存到硬盘:
maxElementsOnDisk:
默认为0,无限多。ehcache_failsafe.xml为10000000。
diskExpiryThreadIntervalSeconds:
使用过期算法清除磁盘中失效对象的间隔,默认为120秒。
diskSpoolBufferSizeMB:
默认为30M。
重启时缓存持久化:
diskPersistent:
当应用重启时,可将缓存先持久化到硬盘,重启后再行载入,节省大量的重新从数据库载入。但只适合那些缓存不怎么变化,
或者有特殊机制保证重\启后应用能接收到重启这段时间里缓存变化信息的情况。
cacheEventListenerFactory配置:
replicateAsynchronously:
对象同步是否异步完成,默认为true。如果比较紧急就设为false。 在一致性时间性要求不强的时候,设为异步可大大提供性能,
因为它是异步立即返回的,而且可以批量提交。
replicateUpdatesViaCopy:
是否将对象变更复制到所有节点,还是只是发送一个失效信息,让对方该缓存失效,当对方需要该缓存时重新计算载入。
默认为true。鉴于对象复制的消耗挺大的,又有锁的问题,而且对方也未必需要该对象,所以此属性建议设为false。
如果业务上真的需要设为true时,就可考虑使用Terracotta了。
replicatePuts:
增加对象时是否同步,默认为true,如果replicateUpdatesViaCopy为false,选择了失效算法,所以replicatePuts 要设为false。
replicateUpdates:
修改加对象时是否同步,默认为true
replicateRemovals:
删除加对象时是否同步,默认为true
-->
<!-- 缓存同步jgroup配置 -->
<!-- 参数示例:
connect=TCP(bind_addr=$[jg_address1];bind_port=$[jg_port1])
这里配置的是当前机器的 ip 和绑定的端口号
TCPPING(initial_hosts=$[jg_address1][$[jg_port1]],$[jg_address2][$[jg_port2]]
这里配置的是当前集群下所有的 ip 和端口号列表
例如:集群中有两台机器其中一台 ip 192.168.1.45,一台是192.168.1.46
那么这两台Ehcache的配置如下:
192.168.1.45
properties="connect=TCP(bind_addr=192.168.1.45;bind_port=7800):
TCPPING(initial_hosts=192.168.1.45[7800],192.168.1.46[7800];
-->
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
properties="connect=TCP(bind_addr=$[jg_address1];bind_port=$[jg_port1]):
TCPPING(initial_hosts=$[jg_address1][$[jg_port1]],$[jg_address2][$[jg_port2]];
port_range=10;timeout=5000;num_initial_members=2):MERGE2(min_interval=3000;max_interval=5000):
FD_ALL(interval=5000;timeout=20000):FD(timeout=5000;max_tries=48;):VERIFY_SUSPECT(timeout=1500):
pbcast.NAKACK(retransmit_timeout=100,200,300,600,1200,2400,4800;discard_delivered_msgs=true):
pbcast.STABLE(stability_delay=1000;desired_avg_gossip=20000;max_bytes=0):pbcast.GMS(print_local_addr=true;join_timeout=5000)"
propertySeparator="::"/>
<diskStore path="java.io.tmpdir/ehcache"/>
<defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="true"
memoryStoreEvictionPolicy="LRU"
maxElementsOnDisk="10000000" diskExpiryThreadIntervalSeconds="600"
diskPersistent="false"
>
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true" />
</defaultCache>
<!-- shiro授权的缓存名称 -->
<cache name="xxx_admin_shiroAuthorizationCache" maxElementsInMemory="10000" timeToLiveSeconds="3600">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true" />
</cache>
<!-- shiro认证的缓存名称 -->
<cache name="xxx_admin_shiroAuthenticationCache" maxElementsInMemory="10000" timeToLiveSeconds="3600" memoryStoreEvictionPolicy="LRU">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true" />
</cache>
<!-- shiro的活动session缓存名称 -->
<cache name="xxx_admin_shiroActiveSessionCache" maxElementsInMemory="10000" timeToLiveSeconds="3600" memoryStoreEvictionPolicy="LRU">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true" />
</cache>
</ehcache>
ehcache jgroup 分布式配置
最新推荐文章于 2020-12-16 14:50:28 发布