🐛 修复删除文章或者评论后出现的异常

pull/21/head
ruibaby 2018-07-19 17:55:09 +08:00
parent 5add534464
commit 006d538f22
2 changed files with 8 additions and 4 deletions

View File

@ -24,6 +24,8 @@ public class CommentServiceImpl implements CommentService {
private static final String COMMENTS_CACHE_NAME = "comments";
private static final String POSTS_CACHE_NAME = "posts";
@Autowired
private CommentRepository commentRepository;
@ -33,7 +35,7 @@ public class CommentServiceImpl implements CommentService {
* @param comment comment
*/
@Override
@CacheEvict(value = COMMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
@CacheEvict(value = {COMMENTS_CACHE_NAME, POSTS_CACHE_NAME}, allEntries = true, beforeInvocation = true)
public void saveByComment(Comment comment) {
commentRepository.save(comment);
}
@ -45,7 +47,7 @@ public class CommentServiceImpl implements CommentService {
* @return Optional
*/
@Override
@CacheEvict(value = COMMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
@CacheEvict(value = {COMMENTS_CACHE_NAME, POSTS_CACHE_NAME}, allEntries = true, beforeInvocation = true)
public Optional<Comment> removeByCommentId(Long commentId) {
Optional<Comment> comment = this.findCommentById(commentId);
commentRepository.delete(comment.get());

View File

@ -32,6 +32,8 @@ public class PostServiceImpl implements PostService {
private static final String POSTS_CACHE_NAME = "posts";
private static final String COMMENTS_CACHE_NAME = "comments";
@Autowired
private PostRepository postRepository;
@ -42,7 +44,7 @@ public class PostServiceImpl implements PostService {
* @return Post
*/
@Override
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
@CacheEvict(value = {POSTS_CACHE_NAME, COMMENTS_CACHE_NAME}, allEntries = true, beforeInvocation = true)
public Post saveByPost(Post post) {
return postRepository.save(post);
}
@ -54,7 +56,7 @@ public class PostServiceImpl implements PostService {
* @return Post
*/
@Override
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
@CacheEvict(value = {POSTS_CACHE_NAME, COMMENTS_CACHE_NAME}, allEntries = true, beforeInvocation = true)
public Post removeByPostId(Long postId) {
Optional<Post> post = this.findByPostId(postId);
postRepository.delete(post.get());