|
|
package com.yohoufo.common.cache;
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
|
...
|
...
|
@@ -72,18 +73,20 @@ public class ControllerCacheAop implements ApplicationContextAware{ |
|
|
public Object cacheAop(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
|
|
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
|
|
|
|
|
Method method = signature.getMethod();
|
|
|
//方法名称
|
|
|
final String methodName = signature.getMethod().getName();
|
|
|
final String methodName = method.getName();
|
|
|
//返回类型
|
|
|
final Class<?> returnType = signature.getMethod().getReturnType();
|
|
|
final Class<?> returnType = method.getReturnType();
|
|
|
|
|
|
logger.debug("Enter controller pointcut: {}", methodName);
|
|
|
|
|
|
//some info
|
|
|
Cachable cacheExpire = signature.getMethod().getAnnotation(Cachable.class);
|
|
|
Cachable cacheExpire = method.getAnnotation(Cachable.class);
|
|
|
|
|
|
//caculate cache key
|
|
|
final String level1_cache_key = this.getL1CacheKey(joinPoint, cacheExpire);
|
|
|
final String level1_cache_key = this.getL1CacheKey(method, joinPoint.getArgs());
|
|
|
//final String level2_cache_key = this.getL2CacheKey(joinPoint, cacheExpire);
|
|
|
|
|
|
|
...
|
...
|
@@ -116,6 +119,11 @@ public class ControllerCacheAop implements ApplicationContextAware{ |
|
|
return httpResponse;
|
|
|
}
|
|
|
|
|
|
public void clearCache(Method method, Object[] params) {
|
|
|
String key = getL1CacheKey(method, params);
|
|
|
this.cacheClient.delete(key);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 将结果保存在缓存中
|
|
|
* @param level1_cache_key
|
...
|
...
|
@@ -150,9 +158,10 @@ public class ControllerCacheAop implements ApplicationContextAware{ |
|
|
* @param cacheExpire
|
|
|
* @return key
|
|
|
*/
|
|
|
private String getL1CacheKey(ProceedingJoinPoint joinPoint, Cachable cacheExpire) {
|
|
|
private String getL1CacheKey(Method method, Object[] params) {
|
|
|
Cachable cacheExpire = method.getAnnotation(Cachable.class);
|
|
|
int[] excludeParams = cacheExpire.excludeArgs();
|
|
|
String cacheKey = this.getCacheKey(joinPoint, excludeParams);
|
|
|
String cacheKey = this.getCacheKey(method.getName(), params, excludeParams);
|
|
|
|
|
|
String level1_cache_key = "YH:UFOGW:L1:" + cacheKey;
|
|
|
|
...
|
...
|
@@ -172,14 +181,13 @@ public class ControllerCacheAop implements ApplicationContextAware{ |
|
|
}
|
|
|
|
|
|
|
|
|
private String getCacheKey(ProceedingJoinPoint joinPoint, int[] excludeParams ){
|
|
|
private String getCacheKey(String methodName, Object params[], int[] excludeParams ){
|
|
|
|
|
|
//args params sign
|
|
|
Object arguments[] = joinPoint.getArgs();
|
|
|
String args_sign = this.getStrings(arguments, excludeParams);
|
|
|
String args_sign = this.getStrings(params, excludeParams);
|
|
|
|
|
|
//method name
|
|
|
String cacheKeyPrefix = "yh_ufogw:" + joinPoint.getSignature().getName();
|
|
|
String cacheKeyPrefix = "yh_ufogw:" + methodName;
|
|
|
|
|
|
return cacheKeyPrefix + ":" + args_sign;
|
|
|
}
|
...
|
...
|
|