Skip to content

Commit

Permalink
🐛 修复修改标签/分类信息之后,文章信息没有刷新的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Dec 6, 2018
1 parent 0bf5793 commit 1501bda
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand All @@ -21,6 +22,8 @@
@Service
public class CategoryServiceImpl implements CategoryService {

private static final String POSTS_CACHE_NAME = "posts";

@Autowired
private CategoryRepository categoryRepository;

Expand All @@ -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);
}
Expand All @@ -42,6 +46,7 @@ public Category saveByCategory(Category category) {
* @return Category
*/
@Override
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
public Category removeByCateId(Long cateId) {
Optional<Category> category = this.findByCateId(cateId);
categoryRepository.delete(category.get());
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/cc/ryanc/halo/service/impl/TagServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand All @@ -21,6 +22,8 @@
@Service
public class TagServiceImpl implements TagService {

private static final String POSTS_CACHE_NAME = "posts";

@Autowired
private TagRepository tagRepository;

Expand All @@ -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);
}
Expand All @@ -42,6 +46,7 @@ public Tag saveByTag(Tag tag) {
* @return Tag
*/
@Override
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
public Tag removeByTagId(Long tagId) {
Optional<Tag> tag = findByTagId(tagId);
tagRepository.delete(tag.get());
Expand Down

0 comments on commit 1501bda

Please sign in to comment.