//设置缓存
privatevoidsetCache(LongtimeOut,TimeUnittimeUnit,Stringkey,Objectresult)throwsException{
if(timeOut.equals(0L)){
stringRedisTemplate.opsForValue().set(key,JsonUtils.toJson(result));
}else{
stringRedisTemplate.opsForValue().set(key,JsonUtils.toJson(result),timeOut,timeUnit);
}
}
//查询缓存
privateObjectqueryCache(longstart,StringmethodName,Stringkey)throwsException{
//缓存的接口返回结果必须是RSResponse
Objectresult=JsonUtils.toBean(RSResponse.class,stringRedisTemplate.opsForValue().get(key));
longtime=System.currentTimeMillis()-start;
logger.info("RESTAPIMethod【Cache】:"+methodName+",Time:"+time+"ms");
returnresult;
}