diff --git a/src/main/java/cc/ryanc/halo/service/impl/CommentServiceImpl.java b/src/main/java/cc/ryanc/halo/service/impl/CommentServiceImpl.java index 1385aa02a..ca7786d32 100644 --- a/src/main/java/cc/ryanc/halo/service/impl/CommentServiceImpl.java +++ b/src/main/java/cc/ryanc/halo/service/impl/CommentServiceImpl.java @@ -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 removeByCommentId(Long commentId) { Optional comment = this.findCommentById(commentId); commentRepository.delete(comment.get()); diff --git a/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java b/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java index e825078d2..076c7bf94 100755 --- a/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java +++ b/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java @@ -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 = this.findByPostId(postId); postRepository.delete(post.get());