🐛 修复修改标签/分类信息之后,文章信息没有刷新的问题

pull/69/head
ruibaby 2018-12-06 20:36:32 +08:00
parent 0bf579327a
commit 1501bdad25
2 changed files with 10 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.repository.CategoryRepository; import cc.ryanc.halo.repository.CategoryRepository;
import cc.ryanc.halo.service.CategoryService; import cc.ryanc.halo.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
@ -21,6 +22,8 @@ import java.util.Optional;
@Service @Service
public class CategoryServiceImpl implements CategoryService { public class CategoryServiceImpl implements CategoryService {
private static final String POSTS_CACHE_NAME = "posts";
@Autowired @Autowired
private CategoryRepository categoryRepository; private CategoryRepository categoryRepository;
@ -31,6 +34,7 @@ public class CategoryServiceImpl implements CategoryService {
* @return Category * @return Category
*/ */
@Override @Override
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
public Category saveByCategory(Category category) { public Category saveByCategory(Category category) {
return categoryRepository.save(category); return categoryRepository.save(category);
} }
@ -42,6 +46,7 @@ public class CategoryServiceImpl implements CategoryService {
* @return Category * @return Category
*/ */
@Override @Override
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
public Category removeByCateId(Long cateId) { public Category removeByCateId(Long cateId) {
Optional<Category> category = this.findByCateId(cateId); Optional<Category> category = this.findByCateId(cateId);
categoryRepository.delete(category.get()); categoryRepository.delete(category.get());

View File

@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.Tag;
import cc.ryanc.halo.repository.TagRepository; import cc.ryanc.halo.repository.TagRepository;
import cc.ryanc.halo.service.TagService; import cc.ryanc.halo.service.TagService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
@ -21,6 +22,8 @@ import java.util.Optional;
@Service @Service
public class TagServiceImpl implements TagService { public class TagServiceImpl implements TagService {
private static final String POSTS_CACHE_NAME = "posts";
@Autowired @Autowired
private TagRepository tagRepository; private TagRepository tagRepository;
@ -31,6 +34,7 @@ public class TagServiceImpl implements TagService {
* @return Tag * @return Tag
*/ */
@Override @Override
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
public Tag saveByTag(Tag tag) { public Tag saveByTag(Tag tag) {
return tagRepository.save(tag); return tagRepository.save(tag);
} }
@ -42,6 +46,7 @@ public class TagServiceImpl implements TagService {
* @return Tag * @return Tag
*/ */
@Override @Override
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
public Tag removeByTagId(Long tagId) { public Tag removeByTagId(Long tagId) {
Optional<Tag> tag = findByTagId(tagId); Optional<Tag> tag = findByTagId(tagId);
tagRepository.delete(tag.get()); tagRepository.delete(tag.get());