Object[] arguments = joinPoint.getArgs();
//试图得到标注的Ehcache类
@SuppressWarnings("unused")
Method[] methods = joinPoint.getTarget().getClass().getMethods();
Ehcache flag = null;
for(Method m:methods){
if(m.getName().equals(methodName)){
Class[] tmpCs = m.getParameterTypes();
if(tmpCs.length==arguments.length){
flag = m.getAnnotation(Ehcache.class);
break;
}
}
}
if(flag==null){
return null;
}
//Ehcache flag =joinPoint.getTarget().getClass().getMethod(methodName).getAnnotation(Ehcache.class);
Object result;
String cacheKey = getCacheKey(targetName, methodName, arguments);
Element element = null;
if(flag.eternal()){
//永久缓存
element = dictCache.get(cacheKey);
}else{
//临时缓存
element = eternalCache.get(cacheKey);
}
if (element == null) {
if ((arguments != null) && (arguments.length != 0)) {
result = joinPoint.proceed(arguments);
} else {
result = joinPoint.proceed();
}
element = new Element(cacheKey, (Serializable) result);
if(flag.eternal()){
//永久缓存
dictCache.put(element);
}else{
//临时缓存
eternalCache.put(element);