主要使用Spring提供的springmodules和EHCache来简化程序的开发,通过配置文件来完成提供缓存。参考springmodules的文档。
参考
基于springmodules的缓存方案
一 基于xml配置和拦截
主要步骤
1、配置ehcache.xml文件
2、创建Spring EHCache的配置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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd">
<bean id="EhCacheFacade"
class="org.springmodules.cache.provider.ehcache.EhCacheFacade">
<property name="failQuietlyEnabled" value="true" />
<property name="cacheManager">
<bean
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation"
value="classpath:ehcache.xml">
</property>
</bean>
</property>
</bean>
<bean id="cachingInterceptor"
class="org.springmodules.cache.interceptor.caching.MethodMapCachingInterceptor">
<property name="cacheProviderFacade" ref="EhCacheFacade" />
<property name="cachingModels">
<props>
<prop key="com....test.Manager.get*">
cacheName=dictCache
</prop>
</props>
</property>
</bean>
<bean id="flushingInterceptor"
class="org.springmodules.cache.interceptor.flush.MethodMapFlushingInterceptor">
<property name="cacheProviderFacade" ref="EhCacheFacade" />
<property name="flushingModels">
<props>
<prop key="com....test.Manager.update*">
cacheNames=dictCache
</prop>
</props>
</property>
</bean>
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>*anager</value>
</property>
<property name="interceptorNames">
<list>
<value>flushingInterceptor</value>
<value>cachingInterceptor</value>
</list>
</property>
</bean>
<bean id="manager" class="com...test.Manager"></bean>
</beans>
<cache name="dictCache"
maxElementsInMemory="50"
eternal="false"
timeToIdleSeconds="60"
timeToLiveSeconds="60"
overflowToDisk="false"
memoryStoreEvictionPolicy="LFU">
</cache>
缓存说明:
1、方法不含有参数
时间到期缓存失效;调用flush,缓存失效。
2、方法中含有参数
参数不同则每次都缓存,若缓存中存在相同对象,则调用缓存。
当调用flush,该id对应的缓存都失效。
当缓存时间到期,该id对应的缓存都失效。
建议:对没有关联的缓存对象采取不同的id配置。所以ehcache会有好多的cache-id配置信息。
<props>
<prop key="com....test.Manager.get*">
cacheName=dictCache
</prop>
………
<prop key="com....test.Manager2.get*">
cacheName=dictCache2
</prop>
</props>
<props>
<prop key="com....test.Manager.update*">
cacheNames=dictCache
</prop>
………
<prop key="com....test.Manager2.update*">
cacheNames=dictCache2
</prop>
</props>
二 基于注解
详见下面的一篇文章,已经很详细了
使用spring-modules-0.9实现注解缓存
分享到:
相关推荐
spring整合ehcache的入门级别demo分享,通过junit来测试
主要介绍了JavaWeb开发之Spring+SpringMVC+MyBatis+SpringSecurity+EhCache+JCaptcha 完整Web基础框架的相关资料,需要的朋友可以参考下
循序渐进,学习Spring Boot、Spring Boot & Shiro、Spring Cloud、Spring Security & Spring Security OAuth2,博客Spring系列源码 一、Spring Boot教程 开启Spring Boot Spring Boot基础配置 Spring Boot中使用...
此项目为springmvc、Mybatis、EHcache、maven、Spring security3、activiti5工作流的整合 是一个基于数据库的权限管理demo项目、使用mysql数据库 项目运行前需要构建maven私服 而且有些jar包私服中肯定没有,需要...
这是一个shiro的入门Demo.. 使用了Spring MVC,mybaits等技术.. 数据库设计 : User : name--password Role : id--userid--roleName Function : id--userid--url tinys普通用户只能访问index.jsp admin用户通过添加...
Spring Boot JPA 二级缓存(ehcache) Spring Boot Hikari 连接池详解 Spring Boot Caffeine 本地缓存 Spring Boot Redis 缓存 Spring Boot Redis 分布式锁 Spring Boot Event 事件发布与监听 Spring Boot 集成 ...
- Spring Boot 缓存,包括redis、ehcache、spring-cache、memcached、使用redis实现session共享 等。 - springboot-templates - Spring Boot 模板,包括thymeleaf、freemarker、jsp、表单校验 等。 - ...
完全由Spring接管DWR AJAX处理(不需要配置dwr.xml)等技术点 源码在/mytest/WEB-INF/src下 Winxp sp3+JDK1.6+Tomcat 6.0下运行通过 因文件长度限制,未加入相关类库,请自行加入,需要的类库有: dom.jar...
本项目作为Spring Boot入门样例,从浅到深用样例学习Spring Boot,并集成Spring Boot常用功能。 入门级功能:包括属性(配置),JDBC模板(数据库CRUD),JPA(Hibernate数据库CRUD),Mybatis(数据库CRUD),...
2、采用Spring 3中最新最稳定的Spring MVC 3.2.8版本。 3、采用Hibernate 4.1.7。Spring MVC 3.2.8支持的最高Hibernate版本是4.1.7,更高的Hibernate版本和Spring MVC 3.2.8组合会遇到兼容问题。 4、Hibernate集成二...
基于SpringMVC+Shiro+Activiti 5.16 的简单OA,...Shiro实现登录认证和权限控制,结合Ehcache缓存权限列表,毕竟权限表并不是总在变化。 用户在线列表,可以强制踢出。Shiro的密码的加密解密,并发登陆、会话管理等功能
在传统Spring应用中使用spring-boot-actuator模块提供监控端点 Spring Boot应用的后台运行配置 Spring Boot自定义Banner Dubbo进行服务治理 chapter9-2-1:Spring Boot中使用Dubbo进行服务治理 chapter9-2-2:Spring...
基础入门 └── Web开发 └── Weex └── Bootstrap └── thymeleaf └── 缓存使用 └── Ehcache └── Caffeine └── Guava Cache └── 数据库 └── Mybatis └── MySQL └── Spring其他功能 ...
aop.jar spring-dao.jar spring-hibernate.jar spring-jdbc.jar spring-mock.jar spring-orm.jar spring-remoting.jar spring-support.jar spring-webmvc.jar
二、快速入门 1 2.1、创建一个Maven工程 1 2.2、pom文件引入依赖 2 2.3、编写HelloWorld服务 2 2.4、@RestController 3 2.5、@EnableAutoConfiguration 3 2.6 SpringApplication.run(HelloController.class, ...
完全响应式权限管理系统,包括用户管理、角色管理,权限管理等功能,适合javaweb开发者入门学习,也可直接用于项目,省去重复开发权限管理模块,提高开发效率,项目使用主流技术如下: 服务端: Spring4.3.0....
springMVC做的小项目,springMVC+spring+hibernate+ehcache+shiro jar包全,代码也全,结构清晰明了,非常适合springMVC初学者、ehcache初学者、shiro初学者。shiro除了做认证以及授权外,还做了并发登录控制,多个...
二、快速入门 2 2.1、创建一个Maven工程 2 2.2、pom文件引入依赖 3 2.3、编写HelloWorld服务 3 2.4、@RestController 4 2.5、@EnableAutoConfiguration 4 2.6 SpringApplication.run(HelloController.class, ...
服务网关,对外暴露统一规范的接口和包装响应结果,包括各个子系统的交互接口、对外开放接口、开发加密接口、接口文档等服务,可在该模块支持验签、鉴权、路由、限流、监控、容错、日志等功能。示例图: ![API网关]...
该博客系统综合运用了作者发表的《 Spring Boot入门》系列的文章引用的知识内容,初学者可以阅读文章以及结合该项目学习。 与作者一样,使用hexo但苦于没有后台管理工具(界面)管理文章的写作者。该博客系统模仿...