zl程序教程

您现在的位置是:首页 >  后端

当前栏目

java缓存设置_缓存数据可以清除吗

JAVA缓存 设置 可以 清除 缓存数据
2023-06-13 09:14:52 时间

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>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/186073.html原文链接:https://javaforall.cn