1、@Cacheable(key = "#vo.toString()", value="licence") //载入缓存
2、@CacheEvict(key = "#vo.toString()",value="licence") //清除缓存
3、缓存设置在service层生效
4、config目录下建ehcache.xml
5、ehcache.xml配置如下
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" updateCheck="false"
xsi:noNamespaceSchemaLocation="http://ehcache.sf.net/ehcache.xsd">
<diskStore path="java.io.tmpdir/ehcache"/>
<!-- 默认的管理策略
maxElementsOnDisk: 在磁盘上缓存的element的最大数目,默认值为0,表示不限制。
eternal:设定缓存的elements是否永远不过期。如果为true,则缓存的数据始终有效,如果为false那么还要根据timeToIdleSeconds,timeToLiveSeconds判断。
diskPersistent: 是否在磁盘上持久化。指重启jvm后,数据是否有效。默认为false。
diskExpiryThreadIntervalSeconds:对象检测线程运行时间间隔。标识对象状态(过期/持久化)的线程多长时间运行一次。
-->
<defaultCache maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="3600"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"/>
<!-- 对象无过期,一个10000长度的队列,最近最少使用的对象被删除 -->
<cache name="sample"
maxElementsInMemory="10000"
eternal="true"
overflowToDisk="true"
diskPersistent="false"
memoryStoreEvictionPolicy="LFU">
</cache>
<cache name="licence"
maxElementsInMemory="10000"
eternal="true"
overflowToDisk="true"
diskPersistent="false"
memoryStoreEvictionPolicy="LFU">
</cache>
</ehcache>