Commit a016a8f0 authored by 张辰's avatar 张辰
parents c1faad0a 7cb189b4
......@@ -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());
}
......@@ -125,7 +125,9 @@ public class CommentService {
}
commentEntity.setReportStatus(ReportStatusEnum.REPORTED.getCode());
commentMapper.updateById(commentEntity);
redisCache.evict(StringUtils.joinWith("_", CAHCE_COMMENT_ID, commentId));
//失效缓存
evictThemeCache(commentEntity.getThemeId());
}
//删除评论
......@@ -137,8 +139,14 @@ public class CommentService {
}
commentEntity.setDeleteTag(DeleteTagEnum.DELETED.getCode());
commentMapper.updateById(commentEntity);
//删除主题的评论列表缓存
redisCache.evict(StringUtils.joinWith("_", CAHCE_COMMENT_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