Spring Cache集成ehcache
来源:互联网 发布:工程造价在国企知乎 编辑:程序博客网 时间:2024/04/28 17:28
EHCache支持内存和磁盘的缓存,支持LRU、LFU和FIFO多种淘汰算法,支持分布式的Cache,可以作为Hibernate的缓存插件。同时它也能提供基于Filter的Cache,该Filter可以缓存响应的内容并采用Gzip压缩提高响应速度。
可以通过spring集成提供缓存管理,spring为ehcache提供了如下的实现类:
EhCacheCache实现Cache接口
EhCacheCacheManager实现CacheManager接口
EhCache工厂管理类
EhCacheFactoryBean
EhCacheManagerFactoryBean
1.引入ehcache jar包
<dependency><groupId>net.sf.ehcache</groupId><artifactId>ehcache-core</artifactId><version>2.6.6</version></dependency>
2.ehcache配置
<?xml version="1.0" encoding="UTF-8"?><ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"monitoring="autodetect"><!-- <diskStore path="java.io.tmpdir" /> --><diskStore path="C:/cache_tmpdir" /><defaultCache maxElementsInMemory="10000" eternal="false"timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"maxElementsOnDisk="10000000" diskPersistent="false"diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" /><cache name="userCache" maxElementsInMemory="10000"maxElementsOnDisk="1000" eternal="false" overflowToDisk="true"diskSpoolBufferSizeMB="20" timeToIdleSeconds="300" timeToLiveSeconds="600"memoryStoreEvictionPolicy="LFU" /></ehcache>3.spring配置
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cache="http://www.springframework.org/schema/cache"xmlns:p="http://www.springframework.org/schema/p"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/cachehttp://www.springframework.org/schema/cache/spring-cache.xsd"><!-- 启用缓存注解功能,这个是必须的,否则注解不会生效,另外,该注解一定要声明在spring主配置文件中才会生效 --><cache:annotation-driven cache-manager="cacheManager" /><bean id="userService" class="org.springframework.cache.demo.UserService" /><!-- cacheManager工厂类,指定ehcache.xml的位置 --><bean id="cacheManagerFactory"class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"p:configLocation="classpath:ehcache.xml" /><!-- 声明cacheManager --><bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"p:cacheManager-ref="cacheManagerFactory" /></beans>
参考文章:
1.Spring3.1 Cache注解
2.Spring实战之Cache
3.Ehcache 整合Spring 使用页面、对象缓存
0 0
- Spring Cache集成ehcache
- Spring-Boot (四) cache/ehcache/redis-cache集成使用
- Spring + Cache/Ehcache
- spring cache和ehcache
- spring注解集成ehcache
- spring 集成 ehcache
- spring注解集成ehcache
- Spring集成ehcache
- Spring集成ehcache
- spring集成Ehcache
- Spring集成ehcache
- spring集成ehcache
- spring集成ehcache
- spring boot 集成EHCache
- Spring使用Cache、整合Ehcache
- Spring使用Cache、整合Ehcache
- Spring使用Cache、整合Ehcache
- Spring使用Cache、整合Ehcache
- 工作问题
- 黑马程序员——Java基础---多线程
- 如何在Mac OS X上安装 Ruby运行环境
- 99 thinkphp ERR_CONTENT_DECODING_FAILED
- Spring Cache集成spring默认缓存实现
- Spring Cache集成ehcache
- 学车知识整理
- 写一个python程序调用windows下django开发服务器
- Spring Cache集成memcached
- C语言选择排序与冒泡排序
- Spring Cache集成redis
- 同一个控制器中无法获取session
- php操作大缓存的存储与读取
- error C2664: “CSerialPort::InitPort”: 不能将参数 1 从“CCom_TestDlg *const ”转换为“HWND”