8.11 缓存优化bug解决
This commit is contained in:
parent
45fd2f6534
commit
61e633f88e
@ -215,6 +215,7 @@ public class PictureController {
|
||||
// /**
|
||||
// * 分页获取图片列表(封装类,脱敏),普通用户使用,且不能看到未过审的图片
|
||||
// */
|
||||
// @Deprecated
|
||||
// @PostMapping("/list/page/vo")
|
||||
// public BaseResponse<Page<PictureVO>> listPictureVOByPage(@RequestBody PictureQueryRequest pictureQueryRequest,
|
||||
// HttpServletRequest request) {
|
||||
@ -251,7 +252,6 @@ public class PictureController {
|
||||
/**
|
||||
* 分页获取图片列表(封装类,有缓存)
|
||||
*/
|
||||
@Deprecated
|
||||
@PostMapping("/list/page/vo")
|
||||
public BaseResponse<Page<PictureVO>> listPictureVOByPageWithCache(
|
||||
@RequestBody PictureQueryRequest pictureQueryRequest,
|
||||
|
@ -36,7 +36,6 @@ public class MyCacheManager {
|
||||
*/
|
||||
private final StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
// ====== 新增:强类型版本 ======
|
||||
public <T> T getFromCacheOrDatabase(
|
||||
String cacheKey,
|
||||
TypeReference<T> typeRef,
|
||||
|
@ -6,6 +6,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@ -618,12 +619,21 @@ public class PictureServiceImpl extends ServiceImpl<PictureMapper, Picture>
|
||||
ThrowUtils.throwIf(!hasPermission, ErrorCode.NO_AUTH_ERROR);
|
||||
}
|
||||
|
||||
// 把查询条件序列化成 JSON
|
||||
String queryJson = JSONUtil.toJsonStr(Map.of(
|
||||
"spaceId", spaceId == null ? "public" : spaceId,
|
||||
"category", queryRequest.getCategory(),
|
||||
"tags", queryRequest.getTags(),
|
||||
"searchText", queryRequest.getSearchText(),
|
||||
"current", current,
|
||||
"size", size
|
||||
));
|
||||
|
||||
String cacheKey = "smilepicture:listPictureVOByPage:spaceId:" + (spaceId == null ? "public" : spaceId) +
|
||||
":current:" + current +
|
||||
":size:" + size;
|
||||
// 计算 MD5 作为哈希(也可用 SHA256)
|
||||
String hash = DigestUtil.md5Hex(queryJson);
|
||||
|
||||
// String cacheKey = "smilepicture:list:v" + ver + ":" + hash;
|
||||
// 拼接缓存 key
|
||||
String cacheKey = "smilepicture:listPictureVOByPage:v1:" + hash;
|
||||
// 随机过期:300–600s
|
||||
int expire = 300 + RandomUtil.randomInt(0, 300);
|
||||
|
||||
|
@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import edu.whut.smilepicturebackend.exception.BusinessException;
|
||||
import edu.whut.smilepicturebackend.exception.ErrorCode;
|
||||
import edu.whut.smilepicturebackend.exception.ThrowUtils;
|
||||
import edu.whut.smilepicturebackend.manager.sharding.DynamicShardingManager;
|
||||
import edu.whut.smilepicturebackend.mapper.SpaceMapper;
|
||||
|
||||
import edu.whut.smilepicturebackend.model.dto.space.SpaceAddRequest;
|
||||
|
Loading…
x
Reference in New Issue
Block a user