资 源 简 介
//设置缓存
private void setCache(Long timeOut, TimeUnit timeUnit, String key, Object result) throws Exception {
if (timeOut.equals(0L)) {
stringRedisTemplate.opsForValue().set(key, JsonUtils.toJson(result));
} else {
stringRedisTemplate.opsForValue().set(key, JsonUtils.toJson(result), timeOut, timeUnit);
}
}
//查询缓存
private Object queryCache(long start, String methodName, String key) throws Exception {
//缓存的接口返回结果必须是RSResponse
Object result = JsonUtils.toBean(RSResponse.class, stringRedisTemplate.opsForValue().get(key));
long time = System.currentTimeMillis() - start;
logger.info("REST API Method【Cache】:" + methodName + ",Time:" + time + "ms");
return result;
}