ehcache缓存问题
来源:互联网 发布:sql 截断字符串 编辑:程序博客网 时间:2024/04/29 01:27
步骤:
1.ehcache.xml
<?xml version="1.0" encoding="gbk"?><ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd"> <diskStore path="java.io.tmpdir"/> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="30" timeToLiveSeconds="30" overflowToDisk="false"/> <!-- 配置自定义缓存 maxElementsInMemory:缓存中允许创建的最大对象数 eternal:缓存中对象是否为永久的,如果是,超时设置将被忽略,对象从不过期。 timeToIdleSeconds:缓存数据的钝化时间,也就是在一个元素消亡之前, 两次访问时间的最大时间间隔值,这只能在元素不是永久驻留时有效, 如果该值是 0 就意味着元素可以停顿无穷长的时间。 timeToLiveSeconds:缓存数据的生存时间,也就是一个元素从构建到消亡的最大时间间隔值, 这只能在元素不是永久驻留时有效,如果该值是0就意味着元素可以停顿无穷长的时间。 overflowToDisk:内存不足时,是否启用磁盘缓存。 memoryStoreEvictionPolicy:缓存满了之后的淘汰算法。 注意:一个ehcache.xml中不是只能写一个cache标签,可以根据缓存的对象不同而写多个cache,其他name为其标识位。 --> <cache name="SimplePageCachingFilter" maxElementsInMemory="10000" eternal="false" overflowToDisk="false" timeToIdleSeconds="900" timeToLiveSeconds="1800" memoryStoreEvictionPolicy="LFU" /></ehcache>
参数说明:
name:缓存名称,配置缓存时,通过名称来调用缓存;
maxElementsOnDisk:磁盘中最大缓存的对象数,值为0表示无穷大;
maxElementsInMemory:内存中最大缓存对象数;
eternal:是否不过期,值为true表示永不过期,默认值为false;
timeToLiveSeconds:设置对象允许存在于缓存中的最长时间;
overflowToDisk:当缓存对象数达到了maxElementsInMemory设置的最大值以后,是否允许把溢出的对象写入到磁盘中;
diskSpoolBufferSizeMB:磁盘缓存区大小,默认值30MB;
timeToldleSeconds:设置允许对象处于空闲状态的最长时间,当对象离上次被访问的时间间隔超过了timeToldleSeconds属性值时,
这个对象就会过期,EhCache就会把它从缓存中清空;
memoryStoreEvictionPolicy:当达到maxElementsInMemory限制时,EhCache将会根据指定的策略去清理内存,可选策略有:
LRU(最近最少使用原则)/FIFO(先进先出)/LFU(最少访问次数)
2.spring-ehcache.xml(要配置到web.xml中)
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xmlns:p="http://www.springframework.org/schema/p"xmlns:cache="http://www.springframework.org/schema/cache"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.1.xsd "><!-- Spring EHCACHE 缓存配置 --><cache:annotation-driven cache-manager="ehcacheCacheManager" /><bean id="ehcacheCacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cacheManager-ref="ehcacheManager" /><bean id="ehcacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"><property name="configLocation" value="classpath:ehcache.xml" /></bean> </beans>
3.在需要缓存的类中进行注解
0 0
- ehcache缓存问题
- Ehcache缓存的清理问题
- jeecg 缓存部署问题 - - linux ehcache
- 缓存--ehcache
- EHCACHE缓存
- EhCache 缓存
- ehcache缓存
- Ehcache 缓存
- EhCache缓存
- ehcache缓存
- Ehcache 缓存
- Ehcache缓存
- Ehcache缓存
- 缓存Ehcache
- ehcache缓存
- Ehcache缓存
- 如何通过2级缓存解决性能问题(ehcache)
- 关于Ehcache集群缓存在应用重启后的加载问题
- 操作系统原理笔记
- easyui datagrid 默认选中行(3)
- 菜鸟要起飞
- Eclipse使用技巧
- ASP.Net: EshineASPNet教程-支付机构支付模块
- ehcache缓存问题
- Hawq学习笔记 --- 批量导入sql文件
- asp和jsp和PHP 和xml和css和js和HTML 都是什么区别?
- MyEclipse安装破解与环境配置
- expires缓存技术
- Nginx带宽控制
- A - Black Square
- iOS跳转支付宝 微信支付成功后一直不会返回
- 101. Symmetric Tree