ehcache 配置详解 教程

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false">
    <diskStore path="java.io.tmpdir/EhCacheSpringAnnotationsExampleApp"/>
    <defaultCache
            maxElementsInMemory="1000"
            eternal="false"
            timeToIdleSeconds="300"
            timeToLiveSeconds="600"
            overflowToDisk="true"
            diskSpoolBufferSizeMB="30"
            maxElementsOnDisk="100"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="100"
            memoryStoreEvictionPolicy="LRU"
            statistics="false"
            />
     
     <cache name="itemSearchCache"
            maxElementsInMemory="3000"
            eternal="false"
            timeToIdleSeconds="300"
            timeToLiveSeconds="600"
            overflowToDisk="true"
            diskSpoolBufferSizeMB="30"
            maxElementsOnDisk="100"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="100"
            memoryStoreEvictionPolicy="LFU"
            statistics="false"
            />
     

</ehcache>

<defaultCache>元素:设定缓存默认过期策略;

<cache>元素:设定具体的命名缓存的数据过期策略;

<cache>的属性

            name:缓存名称,通常为缓存对象的类名

            maxElementsInMemory:设置基于内存的缓存可存放对象的最大数目;

            maxElementsOnDisk:设置基于硬盘的缓存可存放对象的最大数目;

            eternal:如果为true,表示对象记过不会过期,此时会忽略timeToIdleSeconds和timeToLiveSeconds属性,默认为false;           

            timeToIdleSeconds:设定允许对象处于空闲状态的最长时间,以秒为单位。当对象自从最近一次被访问后,如果处于空闲状态的时间超过了timeToIdleSeconds属性值,这个对象就会过期。当对象过期,ehCache将把它从缓存中清空。只有当eternal属性为false,该属性才有效。如何该属性值为0,则表示可以无限期地处于空闲状态。

           timeToLiveSeconds:设定对象允许存在于缓存中的最长时间,以秒为单位。当对象自从被存放到缓存中后,如果 处于缓存中的时间超过了timeToLiveSeconds属性值,这个对象就会过期。当对象过期,ehcahe将把它从缓存中清除。只有当eternal属性为false,该属性才有效。如属性值 为0,则表示可以无限期地存放于缓存中。timeToLiveSeconds必须大于timeToIdleSeconds属性,才有意义。

           overflowToDisk:如果为true,表示当基于内在的缓存中的对象数目达到了maxElementsInMemory界限后,会把溢出的对象写到基于硬盘的缓存中。                     

           


           

           





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值