cacheinterceptor.java
来自「采用tapestry的简单OA系统」· Java 代码 · 共 49 行
JAVA
49 行
package com.ejsun.entapps.core.cache;
import java.io.Serializable;
import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author Quake Wang
* @since 2004-5-18
* @version $Revision: 1.1 $
*
**/
public class CacheInterceptor implements MethodInterceptor {
private static final Log log = LogFactory.getLog(CacheInterceptor.class);
private CacheManager cacheManager;
private CacheController cacheController;
public Object invoke(MethodInvocation invocation) throws Throwable {
Cache cache =
cacheManager.getCache(
cacheController.getCacheName(invocation.getMethod()));
String key =
cacheController.getCacheKey(
invocation.getMethod(),
invocation.getArguments());
Element result = cache.get(key);
if (result == null) {
result = new Element(key, (Serializable) invocation.proceed());
cache.put(result);
}
return result.getValue();
}
public void setCacheManager(CacheManager manager) {
cacheManager = manager;
}
public void setCacheController(CacheController controller) {
cacheController = controller;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?