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

修复评论查询

parent 0e9421d1
......@@ -3,12 +3,10 @@ package com.tanpu.community.config;
import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.util.SpringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
import java.util.Arrays;
@Configuration
......@@ -19,7 +17,7 @@ public class CacheConfig {
@Bean
public RedisCache redisCache() {
return new RedisCache.Builder().cacheName("redis").build();
return new RedisCache.Builder().cacheName("community2").build();
}
@Bean
......
......@@ -42,8 +42,8 @@ public class CommentService {
commentEntity.setCommentId(uuidGenHelper.getUuidStr());
commentMapper.insert(commentEntity);
//失效缓存
redisCache.evict(StringUtils.joinWith("_", CACHE_COMMENT_THEMEID, commentEntity.getThemeId()));
redisCache.evict(StringUtils.joinWith("_", CACHE_THEME_ID, commentEntity.getThemeId()));
evictThemeCache(commentEntity.getThemeId());
}
......@@ -124,9 +124,10 @@ public class CommentService {
throw new BizException("评论未找到,id:" + commentId);
}
commentEntity.setReportStatus(ReportStatusEnum.REPORTED.getCode());
commentMapper.updateById(commentEntity);//失效缓存
redisCache.evict(StringUtils.joinWith("_", CACHE_COMMENT_THEMEID, commentEntity.getThemeId()));
redisCache.evict(StringUtils.joinWith("_", CACHE_THEME_ID, commentEntity.getThemeId()));
commentMapper.updateById(commentEntity);
//失效缓存
evictThemeCache(commentEntity.getThemeId());
}
//删除评论
......@@ -139,8 +140,13 @@ public class CommentService {
commentEntity.setDeleteTag(DeleteTagEnum.DELETED.getCode());
commentMapper.updateById(commentEntity);
//失效缓存
redisCache.evict(StringUtils.joinWith("_", CACHE_COMMENT_THEMEID, commentEntity.getThemeId()));
redisCache.evict(StringUtils.joinWith("_", CACHE_THEME_ID, commentEntity.getThemeId()));
evictThemeCache(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