AOP,需要2个拦截器:
1. 一个是方法执行前查找缓存的拦截器;(query方法执行前先查找是否有缓存,如果有,
走缓存,如果没有,执行方法,并且把结果缓存)
2. 另一个是方法执行后销毁缓存的拦截器;(update,insert,delete等方法执行后需要销毁缓
存)
方法执行前的拦截器MethodCacheInterceptor.java:
Java代码
package ehcache;
Import java.io.Serializable;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;
public class MethodCacheInterceptor implements MethodInterceptor, InitializingBean { private static final Log logger = LogFactory.getLog(MethodCacheInterceptor.class);
private Cache cache;
public void setCache(Cache cache) {
this.cache = cache;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(cache, "A cache is required. Use setCache(Cache) to provide one."); }
public Object invoke(MethodInvocation invocation) throws Throwable {
String targetName = invocation.getThis().getClass().getName();
String methodName = invocation.getMethod().getName();
Object[] arguments = invocation.getArguments();
Object result;
Ehcache中文指南和实例教程_互联网_IT/计算机_专业资料。Ehcache 内存框架介绍 1. 背景及基础介绍 目的:使用缓存技术缓解数据库压力,提高访问速度,牺牲内存空间换取...
Spring3 1整合EhCache注解实例_互联网_IT/计算机_专业资料 暂无评价0人阅读0次下载举报文档 Spring3 1整合EhCache注解实例_互联网_IT/计算机_专业资料。 ...
EhCache Server 同时也提供强大的安全机制、监控功能。在数据存储方面,最大的 Ehcache 单实例在内存中可以缓存 20GB。最大的磁盘可以缓存 100GB。通过将节点整合在...
maven + spring + hibernate + mysql + ehcache实例(注解方式实现)_计算机软件及应用_IT/计算机_专业资料。 折腾了2天。 看spring in action看到一半,觉得搭...
具体的实例如下: <cacheManagerPeerProviderFactoryclass="net.sf.ehcache.distribution. RMICacheManagerPeerProviderFactory" properties="peerDiscovery=manual, rmiUrls=//...
支持多缓存管理器实例,以及一个实例的多个缓存区域 提供 Hibernate 的缓存实现 2 安装和使用 2.1 下载 Ehcache 的官方网站http://ehcache.org/downloads/catalog...
下面是 ehcache.xml 具体实例以及配置指南 <ehcache xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance CacheManager 配置 DmulticastGroupPort=4446,这样可以...
EHCache技术文档详解_IT/计算机_专业资料。记录使用EHCache实现页面级的缓存以及...支持多缓存管理器实例,以及一个实例的多个缓存区域 9. 提供 Hibernate 的缓存...
下面是ehcache.xml具体实例以及配置指南 <ehcache xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance · CacheManager配置 DmulticastGroupPort=4446,这样可以...
(6) 支持多缓存管理器实例,以及一个实例的多个缓存区域 2 部署 2.1 引入 官网地址:http://www.ehcache.org/ 下载发布包 ehcache-2.8.1-distribution.tar....
热门文档