private HashMap<String,CacheContainner> cache=new HashMap<String, CacheContainner>();
//不需要判断policy为null,policy为null,认定为不适用缓存,不会掉用此方法
@Override
public boolean ifReturnFromCahce(Method method, Object[] args) {
CachePolicy policy=method.getAnnotation(CachePolicy.class);
if(policy.expires() < 0){
System.out.println("没有有效期,false");
return false;
}
try {
String key=getCacheKey(method,args);
//String key=policy.keyGenerater().newInstance().generatKey(method, args);System.out.println("生成的缓存key:"+key);
if(cache.containsKey(key)==false){System.out.println("有缓存规则,但缓存中不存在false");
return false;
}
CacheContainner cc=cache.get(key);
if((System.currentTimeMillis()-cc.brith) < policy.expires()){System.out.println("有缓存规则,且缓存中存在,且没过期true");
return true;
}
} catch (Exception e) {
e.printStackTrace();
}