From 1501bdad250ff73b1a6c5852d843c113e88fd0fb Mon Sep 17 00:00:00 2001 From: ruibaby Date: Thu, 6 Dec 2018 20:36:32 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=A0=87=E7=AD=BE/=E5=88=86=E7=B1=BB=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B9=8B=E5=90=8E=EF=BC=8C=E6=96=87=E7=AB=A0=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=88=B7=E6=96=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cc/ryanc/halo/service/impl/CategoryServiceImpl.java | 5 +++++ src/main/java/cc/ryanc/halo/service/impl/TagServiceImpl.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/cc/ryanc/halo/service/impl/CategoryServiceImpl.java b/src/main/java/cc/ryanc/halo/service/impl/CategoryServiceImpl.java index 1fc046db5..c032409ec 100755 --- a/src/main/java/cc/ryanc/halo/service/impl/CategoryServiceImpl.java +++ b/src/main/java/cc/ryanc/halo/service/impl/CategoryServiceImpl.java @@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.Category; import cc.ryanc.halo.repository.CategoryRepository; import cc.ryanc.halo.service.CategoryService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -21,6 +22,8 @@ import java.util.Optional; @Service public class CategoryServiceImpl implements CategoryService { + private static final String POSTS_CACHE_NAME = "posts"; + @Autowired private CategoryRepository categoryRepository; @@ -31,6 +34,7 @@ public class CategoryServiceImpl implements CategoryService { * @return Category */ @Override + @CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true) public Category saveByCategory(Category category) { return categoryRepository.save(category); } @@ -42,6 +46,7 @@ public class CategoryServiceImpl implements CategoryService { * @return Category */ @Override + @CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true) public Category removeByCateId(Long cateId) { Optional category = this.findByCateId(cateId); categoryRepository.delete(category.get()); diff --git a/src/main/java/cc/ryanc/halo/service/impl/TagServiceImpl.java b/src/main/java/cc/ryanc/halo/service/impl/TagServiceImpl.java index 14b43a6f8..5bda686f3 100644 --- a/src/main/java/cc/ryanc/halo/service/impl/TagServiceImpl.java +++ b/src/main/java/cc/ryanc/halo/service/impl/TagServiceImpl.java @@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.Tag; import cc.ryanc.halo.repository.TagRepository; import cc.ryanc.halo.service.TagService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -21,6 +22,8 @@ import java.util.Optional; @Service public class TagServiceImpl implements TagService { + private static final String POSTS_CACHE_NAME = "posts"; + @Autowired private TagRepository tagRepository; @@ -31,6 +34,7 @@ public class TagServiceImpl implements TagService { * @return Tag */ @Override + @CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true) public Tag saveByTag(Tag tag) { return tagRepository.save(tag); } @@ -42,6 +46,7 @@ public class TagServiceImpl implements TagService { * @return Tag */ @Override + @CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true) public Tag removeByTagId(Long tagId) { Optional tag = findByTagId(tagId); tagRepository.delete(tag.get());