ehcache缓存机制
来源:互联网 发布:php cs fixer v2.phar 编辑:程序博客网 时间:2024/05/01 13:22
ehcache缓存功能强大,最常用的是和hibernate和mybatis之类的持久层框架一起搭配使用,ehcache还可以缓存某个文件,甚至静态页面。
和hibernate持久层框架配合使用暂时先不说,这里主要演示ehcache.xml文件
<?xml version="1.0" encoding="UTF-8"?><ehcache><diskStore path="java.io.tmpdir" /><defaultCache maxElementsInMemory="500" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="1200" overflowToDisk="true" /><cache name="testcache1" maxElementsInMemory="150" eternal="false" timeToLiveSeconds="36000" timeToIdleSeconds="3600" overflowToDisk="true"/> </ehcache>
1 maxElementsInMemory
如maxElementsInMemory="10000" ,内存中存储的对象的个数, 内存管理的缓存元素数量最大限值。
2 overflowToDisk
如overflowToDisk="true" 对象在内存中达到最大个数的时候,是否写入硬盘
3 eternal
如eternal="false",表示cache中的对象是否过期,缺省为过期(按照配置中的时间),如果改为true,表示该对象永远不过期。
即cache中的元素将一直保存在内存中,不会因为时间超时而丢失,所以在这个值为true的时候,timeToIdleSeconds和timeToLiveSeconds两个属性的值就不起作用了。
4 maxElementsOnDisk
如maxElementsOnDisk="10000000" 在硬盘上最大的对象个数, 硬盘管理的缓存元素数量最大限值。默认值为0,就是没有限制。
5 timeToIdleSeconds
如timeToIdleSeconds="3600" 设定元素在过期前空闲状态的时间,只对非持久性缓存对象有效。默认值为0,值为0意味着元素可以闲置至无限长时间。
访问这个cache中元素的最大间隔时间。如果超过这个时间没有访问这个cache中的某个元素,那么这个元素将被从cache中清除。
6 timeToLiveSeconds
如timeToLiveSeconds="100000" 设定元素从创建到过期的时间。对象存活多少秒过期. 默认值为0,值为0意味着元素可以存活至无限长时间。
意思是从cache中的某个元素从创建到消亡的时间,从创建开始计时,当超过这个时间,这个元素将被从cache中清除。
7 diskPersistent
如diskPersistent="false" 是否持久化磁盘缓存,设定在虚拟机重启时是否进行磁盘存储,默认为false.
要想把cache真正持久化到磁盘,写程序时必须注意,在是用net.sf.ehcache.Cache的void put (Element element)方法后要使用void flush()方法。
8 diskExpiryThreadIntervalSeconds
如diskExpiryThreadIntervalSeconds=”1000”: 访问磁盘线程活动时间。
9 diskSpoolBufferSizeMB
存入磁盘时的缓冲区大小,默认30MB,每个缓存都有自己的缓冲区
10 emoryStoreEvictionPolicy
如: emoryStoreEvictionPolicy=” LRU”,元素逐出缓存规则。共有三种,(LRU)最近最少使用,为默认。
First In First Out (FIFO),先进先出。
Less Frequently Used(specified as LFU)最少使用。
11 name
指定一个cache的名字,用来识别不同的cache,必须惟一。
其中必须要填的属性为:
maxElementsInMemory: maxElementsOnDisk: eternal: overflowToDisk:
- ehcache缓存机制
- ehcache缓存机制
- SpringMvc Ehcache 实现缓存机制
- spring-boot集成ehcache实现缓存机制
- Spring学习之缓存机制EhCache
- Spring学习之缓存机制EhCache---Condition
- Spring学习之缓存机制EhCache---Key
- spring缓存机制(EhCache配置方式)
- 缓存--ehcache
- EHCACHE缓存
- EhCache 缓存
- ehcache缓存
- Ehcache 缓存
- EhCache缓存
- ehcache缓存
- Ehcache 缓存
- Ehcache缓存
- Ehcache缓存
- 搜狗浏览器的移一处异常情况
- 【编程珠玑】第四章 编写正确的程序
- 时区 和 时间
- 《认知与设计——理解UI设计准则》读书笔记
- 转载:哈希查找因何快?我们使用它需要付出什么代价
- ehcache缓存机制
- android 横竖屏切换的生命周期调用,数据保存
- C99结构体指定初始化
- 命令模式
- 避免Android内存泄露
- LAMP配置注意事项
- sql语句增加一列
- Spring_aop切面编程
- 有关获取本机Ip地址