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());