Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
6cb5b693
Commit
6cb5b693
authored
Jul 29, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复评论查询
parent
0e9421d1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
10 deletions
+14
-10
CacheConfig.java
...src/main/java/com/tanpu/community/config/CacheConfig.java
+1
-3
CommentService.java
...main/java/com/tanpu/community/service/CommentService.java
+13
-7
No files found.
community-service/src/main/java/com/tanpu/community/config/CacheConfig.java
View file @
6cb5b693
...
@@ -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
...
...
community-service/src/main/java/com/tanpu/community/service/CommentService.java
View file @
6cb5b693
...
@@ -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
));
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment