前提:
使用环境:详细页面
依赖包:
<dependency>
<groupId>com.googlecode.ehcache-spring-annotations</groupId>
<artifactId>ehcache-spring-annotations</artifactId>
<version>1.2.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.6.6</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>r09</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
使用方法:
在applicationContext中:
<cache:annotation-driven cache-manager="cacheManager"
proxy-target-class="false" mode="proxy" />
<!-- <aop:config proxy-target-class="true"></aop:config> -->
<!-- cacheManager工厂类 -->
<bean id="cacheManagerFactory"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation">
<value>classpath:ehcache.xml</value>
</property>
<property name="shared">
<value>false</value>
</property>
</bean>
<!-- 声明cacheManager -->
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="cacheManagerFactory"></property>
</bean>
2:在dao或者service中需要缓存的方法上加上
@Cacheable("items")
3:在ehcache.xml中加上2注解的cache
<!-- 详细页面 -->
<cache name="items" maxElementsInMemory="100" maxElementsOnDisk="0"
eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="100">
</cache>
4:需要改进的地方
4.1:不放在内存中,而是放在硬盘上。前提是被缓存的内容以及相关类需要实现Serializable接口
4.2:如果相关类中使用了list.subList则需要重新包装subList因为subList没有实现Serializable接口。不能序列化 .
4.3:正常情况下,不能缓存所有内容。因为比如库存等,在更新的时候需要及时更新。
相关推荐
spring3整合EhCache注解实例
Spring与ehcache结合使用,本地缓存的实现
基于公司的项目在Spring中集成Ehcache,并提供EhcaheUtils工具类,并通过Spring的AOP编程实现方法缓存注解话,先奉献出核心代码,需要的朋友可以参考哦!
在Spring+Hibernate集成环境中使用EhCache缓存做的开发测试,在线程中打开数据库查询数据,及关闭数据库后查询数据的结果.
NULL 博文链接:https://luyao123127.iteye.com/blog/1312099
配置ehcache缓存,存储内存的设置,与spring 的整合等
spring,spring mvc,hibernate,ehcache JavaWeb后台框架
Spring Boot中使用EhCache实现缓存支持,介绍整合方法和配置
开源测试项目:spring mvc+springsecurity3+ehcache+bootstrap+mysql 内附MySQL表,直接导入就可运行 效果图请移步:http://blog.csdn.net/yangxuan0261/article/details/10053947
NULL 博文链接:https://cuisuqiang.iteye.com/blog/2050675
NULL 博文链接:https://cczakai.iteye.com/blog/1622708
Spring+EhCache实例源码,本实例的环境 eclipse + maven + spring + ehcache + junit,实例详解请访问博主博客:http://blog.csdn.net/u013142781
以java配置类方式 整合EhCache来实现页面整体缓存及页面局部缓存。详情见博客http://blog.csdn.net/poorCoder_/article/details/56483954
spring整合EhCache 的简单例子
NULL 博文链接:https://greemranqq.iteye.com/blog/2002473
本例子主要讲解ehcache的配置使用。采用了java配置和xml配置两种方式。主要用于学习。 使用java配置时将SpringTestCase.java 文件中的@ContextConfiguration(locations = { "classpath:applicationContext.xml" }) ...
spring,spring mvc,hibernate,ehcache Java后台框架
1)Demo 学习要点简介: ...2.Eclipse 导入后可能需要在 Xml Catalog 手动添加:ehcache-spring-1.2.xsd(ehcache-spring-annotations-1.2.0-sources.jar里面有,自己找下)。 3.内附Oracle建表等可执行语句。
spring+ehcache示例整合Demo
spring集成ehcache所需的jar包