APO缓存接口数据
代码说明:
//设置缓存 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; }
下载说明:请别用迅雷下载,失败请重下,重下不扣分!