Java 缓存设置

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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值