From 006d538f22ae2db29fbd3ac74a1fc2dff46b8f44 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Thu, 19 Jul 2018 17:55:09 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=96=87=E7=AB=A0=E6=88=96=E8=80=85=E8=AF=84=E8=AE=BA=E5=90=8E?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cc/ryanc/halo/service/impl/CommentServiceImpl.java | 6 ++++-- .../java/cc/ryanc/halo/service/impl/PostServiceImpl.java | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) 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());