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