3秒缓存
This commit is contained in:
parent
b39a7f6dc5
commit
bedbdcb0d7
|
|
@ -84,6 +84,11 @@ public class RedisUtils {
|
|||
return this.fromJson(jsonStr, clazz);
|
||||
}
|
||||
|
||||
public <T> T getObjectDate(String key, Class<T> clazz) {
|
||||
String jsonStr = get(key);
|
||||
return this.fromJson(jsonStr, clazz);
|
||||
}
|
||||
|
||||
public String getDate(String key, String method) {
|
||||
if (!this.hasKey(key)) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package com.sqx.modules.course.controller.app;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sqx.common.annotation.Debounce;
|
||||
import com.sqx.common.utils.RedisKeys;
|
||||
import com.sqx.common.utils.RedisUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.course.entity.Course;
|
||||
import com.sqx.modules.course.service.CourseDetailsService;
|
||||
import com.sqx.modules.course.service.CourseService;
|
||||
import com.sqx.modules.sys.controller.AbstractController;
|
||||
|
|
@ -24,6 +26,8 @@ public class AppCourseController extends AbstractController {
|
|||
private CourseService courseService;
|
||||
@Autowired
|
||||
private CourseDetailsService courseDetailsService;
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
@GetMapping("/selectCourse")
|
||||
@ApiOperation("查询短剧信息")
|
||||
|
|
@ -41,10 +45,19 @@ public class AppCourseController extends AbstractController {
|
|||
}
|
||||
|
||||
|
||||
@Login
|
||||
@GetMapping("/selectCourseDetailsById")
|
||||
@ApiOperation("根据id查询短剧详情")
|
||||
// @Debounce(interval = 1000, value = "#id,#token")
|
||||
public Result selectCourseDetailsById(Long id, String token, String courseDetailsId) {
|
||||
public Result selectCourseDetailsById(@RequestAttribute("userId") Long userId, Long id, String token, String courseDetailsId) {
|
||||
String redisKey = RedisKeys.getDateKey("course:") + userId + "-" + id;
|
||||
Object week = redisUtils.getObjectDate(redisKey,Course.class);
|
||||
if (week != null) {
|
||||
return Result.success().put("data", week);
|
||||
}
|
||||
Result result = courseDetailsService.selectCourseDetailsById(id, token, courseDetailsId);
|
||||
if (result.get("code").equals(0)) {
|
||||
redisUtils.set(redisKey, result.get("data"), 3);
|
||||
}
|
||||
return courseDetailsService.selectCourseDetailsById(id, token, courseDetailsId);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue