用户收藏sql优化,接口增加缓存

This commit is contained in:
张松
2025-01-02 10:44:39 +08:00
parent fb00873494
commit 51e3639065
2 changed files with 14 additions and 31 deletions

View File

@@ -14,6 +14,8 @@ import com.sqx.modules.course.entity.CourseDetails;
import com.sqx.modules.course.service.CourseCollectService;
import com.sqx.modules.course.service.CourseDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
@@ -32,6 +34,7 @@ public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectDao, Cour
private ReentrantReadWriteLock reentrantReadWriteLock=new ReentrantReadWriteLock(true);
@Override
@CacheEvict(value = "app:courseCollect", key = "#courseCollect.userId")
public Result insertCourseCollect(CourseCollect courseCollect) {
reentrantReadWriteLock.writeLock().lock();
try {
@@ -95,6 +98,7 @@ public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectDao, Cour
}
@Override
@CachePut(value = "app:courseCollect", key = "#userId")
public Result selectByUserId(Integer page, Integer limit, Long userId,Integer classify) {
Page<Course> pages=new Page<>(page,limit);
IPage<Course> courseIPage = baseMapper.selectCourseByCollect(pages, userId,classify);