Commit 6cb5b693 authored by 刘基明's avatar 刘基明

修复评论查询

parent 0e9421d1
...@@ -3,12 +3,10 @@ package com.tanpu.community.config; ...@@ -3,12 +3,10 @@ package com.tanpu.community.config;
import com.tanpu.community.cache.RedisCache; import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.util.SpringUtils; import com.tanpu.community.util.SpringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
import java.util.Arrays; import java.util.Arrays;
@Configuration @Configuration
...@@ -19,7 +17,7 @@ public class CacheConfig { ...@@ -19,7 +17,7 @@ public class CacheConfig {
@Bean @Bean
public RedisCache redisCache() { public RedisCache redisCache() {
return new RedisCache.Builder().cacheName("redis").build(); return new RedisCache.Builder().cacheName("community2").build();
} }
@Bean @Bean
......
...@@ -42,8 +42,8 @@ public class CommentService { ...@@ -42,8 +42,8 @@ public class CommentService {
commentEntity.setCommentId(uuidGenHelper.getUuidStr()); commentEntity.setCommentId(uuidGenHelper.getUuidStr());
commentMapper.insert(commentEntity); commentMapper.insert(commentEntity);
//失效缓存 //失效缓存
redisCache.evict(StringUtils.joinWith("_", CACHE_COMMENT_THEMEID, commentEntity.getThemeId())); evictThemeCache(commentEntity.getThemeId());
redisCache.evict(StringUtils.joinWith("_", CACHE_THEME_ID, commentEntity.getThemeId()));
} }
...@@ -124,9 +124,10 @@ public class CommentService { ...@@ -124,9 +124,10 @@ public class CommentService {
throw new BizException("评论未找到,id:" + commentId); throw new BizException("评论未找到,id:" + commentId);
} }
commentEntity.setReportStatus(ReportStatusEnum.REPORTED.getCode()); commentEntity.setReportStatus(ReportStatusEnum.REPORTED.getCode());
commentMapper.updateById(commentEntity);//失效缓存 commentMapper.updateById(commentEntity);
redisCache.evict(StringUtils.joinWith("_", CACHE_COMMENT_THEMEID, commentEntity.getThemeId())); //失效缓存
redisCache.evict(StringUtils.joinWith("_", CACHE_THEME_ID, commentEntity.getThemeId())); evictThemeCache(commentEntity.getThemeId());
} }
//删除评论 //删除评论
...@@ -139,8 +140,13 @@ public class CommentService { ...@@ -139,8 +140,13 @@ public class CommentService {
commentEntity.setDeleteTag(DeleteTagEnum.DELETED.getCode()); commentEntity.setDeleteTag(DeleteTagEnum.DELETED.getCode());
commentMapper.updateById(commentEntity); commentMapper.updateById(commentEntity);
//失效缓存 //失效缓存
redisCache.evict(StringUtils.joinWith("_", CACHE_COMMENT_THEMEID, commentEntity.getThemeId())); evictThemeCache(commentEntity.getThemeId());
redisCache.evict(StringUtils.joinWith("_", CACHE_THEME_ID, commentEntity.getThemeId())); }
// 失效关联主题缓存
private void evictThemeCache(String themeId){
redisCache.evict(StringUtils.joinWith("_", CACHE_COMMENT_THEMEID, themeId));
redisCache.evict(StringUtils.joinWith("_", CACHE_THEME_ID, themeId));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment