ehcache_cluster.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<diskStore path="java.io.tmpdir" />
<defaultCache maxElementsInMemory="1000" eternal="true"
overflowToDisk="false" memoryStoreEvictionPolicy="LRU" />
<!-- 集群环境下注意修改 hostName=***.***.*.*** 为应用IP -->
<cacheManagerPeerProviderFactory
class = "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic, multicastGroupAddress=***.***.*.***,multicastGroupPort=4446, timeToLive=32,hostName=***.***.*.***" />
<!-- 集群环境下注意修改 hostName=***.***.*.*** 为应用IP -->
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=***.***.*.***, port=40001,socketTimeoutMillis=2000"/>
<cache name="tempCache" maxElementsInMemory="1000" eternal="false"
overflowToDisk="false" timeToLiveSeconds="120" memoryStoreEvictionPolicy="LRU">
<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>
<cache name="dayCache" maxElementsInMemory="1" eternal="false"
overflowToDisk="true" timeToLiveSeconds="86400" memoryStoreEvictionPolicy="LRU">
<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>
<cache name="foreverCache" maxElementsInMemory="100" eternal="true"
overflowToDisk="true" memoryStoreEvictionPolicy="LRU" >
<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>
<cache name="paramCache" maxElementsInMemory="1000" eternal="true"
overflowToDisk="true" memoryStoreEvictionPolicy="LRU" >
<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>
<cache name="modelRCache" maxElementsInMemory="1" eternal="true"
overflowToDisk="true" memoryStoreEvictionPolicy="LRU" >
<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>
<cache name="licCache" maxElementsInMemory="1" eternal="false"
overflowToDisk="true" timeToLiveSeconds="86400" memoryStoreEvictionPolicy="LRU" >
<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>
<cache name="assetCache" maxElementsInMemory="10" eternal="true"
overflowToDisk="true" memoryStoreEvictionPolicy="LRU" >
<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>
applicationContext-cache.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-lazy-init="true">
<description>Spring缓存配置 </description>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml"/>
</bean>
<bean id="cacheProviderFacade"
class="org.springmodules.cache.provider.ehcache.EhCacheFacade">
<property name="cacheManager" ref="cacheManager" />
</bean>
<bean id="cachingInterceptor"
class="org.springmodules.cache.interceptor.caching.MethodMapCachingInterceptor">
<property name="cacheProviderFacade" ref="cacheProviderFacade" />
<property name="cachingModels">
<props>
<!-- 定义拦截的方法(对定义的方法内容进行数据缓存) -->
<!-- 参数缓存,为永久缓存 -->
<prop key="com.yss.fa.pub.service.ParameterService.getParamList">cacheName=paramCache</prop>
<prop key="com.yss.fa.pub.service.ParameterService.getParamMap">cacheName=paramCache</prop>
</props>
</property>
</bean>
<bean id="flushingInterceptor"
class="org.springmodules.cache.interceptor.flush.MethodMapFlushingInterceptor">
<property name="cacheProviderFacade" ref="cacheProviderFacade" />
<property name="flushingModels">
<props>
<!-- 定义拦截的方法(对定义的方法内容进行数据缓存刷新)-->
<prop key="com.yss.fa.securitypublic.service.DefaultedBondService.add">cacheNames=defaultedBondCache</prop>
<prop key="com.yss.fa.securitypublic.service.DefaultedBondService.update">cacheNames=defaultedBondCache</prop>
<prop key="com.yss.fa.securitypublic.service.DefaultedBondService.del">cacheNames=defaultedBondCache</prop>
<prop key="com.yss.fa.securitypublic.service.DefaultedBondService.check">cacheNames=defaultedBondCache</prop>
<prop key="com.yss.fa.securitypublic.service.DefaultedBondService.unCheck">cacheNames=defaultedBondCache</prop>
</props>
</property>
</bean>
<bean id="ServiceAutoProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<!-- 启用代理设置 -->
<property name="proxyTargetClass">
<value>true</value>
</property>
<!-- ehcache 拦截器 -->
<property name="interceptorNames">
<list>
<value>cachingInterceptor</value>
<value>flushingInterceptor</value>
</list>
</property>
<!-- 缓存代理类 (缓存方法,或者是刷新缓存的方法,都必须配置代理类,否则无法拦截对应的方法) -->
<property name="beanNames">
<list>
<value>parameterService</value>
<value>parameterCommonService</value>
</list>
</property>
</bean>
</beans>
<!--ehcache.xml 说明
name:Cache的名称,必须是唯一的(会把这个cache放到HashMap里)。
maxElementsInMemory:内存中保持的对象数量。
maxElementsOnDisk:DiskStore中保持的对象数量,默认值为0,表示不限制。
eternal:是否是永恒数据,如果是,则它的超时设置会被忽略。
overflowToDisk:如果内存中数据超过内存限制,是否要缓存到磁盘上。
timeToIdleSeconds:对象空闲时间,指对象在多长时间没有被访问就会失效。只对eternal为false的有效。默认值0,表示一直可以访问。
timeToLiveSeconds:对象存活时间,指对象从创建到失效所需要的时间。只对eternal为false的有效。默认值0,表示一直可以访问。
diskPersistent:是否在磁盘上持久化。指重启虚拟机后,数据是否有效。默认为false。
diskExpiryThreadIntervalSeconds:对象检测线程运行时间间隔。标识对象状态的线程多长时间运行一次。
diskSpoolBufferSizeMB:DiskStore使用的磁盘大小,默认值30MB。每个cache使用各自的DiskStore。
memoryStoreEvictionPolicy:如果内存中数据超过内存限制,向磁盘缓存时的策略。默认值LRU,可选FIFO、LFU。
-->
ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<diskStore path="java.io.tmpdir" />
<defaultCache maxElementsInMemory="1000" eternal="true"
overflowToDisk="false" memoryStoreEvictionPolicy="LRU" />
<cache name="tempCache" maxElementsInMemory="1000" eternal="false"
overflowToDisk="false" timeToLiveSeconds="120" memoryStoreEvictionPolicy="LRU" />
<cache name="dayCache" maxElementsInMemory="1" eternal="false"
overflowToDisk="true" timeToLiveSeconds="86400" memoryStoreEvictionPolicy="LRU" />
</ehcache>