parent
2abbece9b5
commit
a1c00dd6fc
@ -0,0 +1,47 @@
|
||||
package com.luoo.comment.listener;
|
||||
|
||||
|
||||
import com.luoo.comment.dao.CommentDao;
|
||||
import com.luoo.comment.pojo.Comment;
|
||||
import constants.Constants;
|
||||
import net.oschina.j2cache.CacheChannel;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@RabbitListener(queues = "userInfoCommentCache")
|
||||
public class UserInfoCommentCacheListener {
|
||||
|
||||
@Autowired
|
||||
private CacheChannel cacheChannel;
|
||||
|
||||
@Autowired
|
||||
private CommentDao commentDao;
|
||||
|
||||
@RabbitHandler
|
||||
public void excuteClearCache(String userId) {
|
||||
List<Comment> commentList = commentDao.findAllByUserId(userId);
|
||||
Set<String> journalIdSet = commentList.parallelStream().map(comment -> comment.getRootJournalId()).collect(Collectors.toSet());
|
||||
Set<String> parentIdSet = commentList.parallelStream().map(comment -> comment.getParentId()).collect(Collectors.toSet());
|
||||
|
||||
journalIdSet.stream().parallel().forEach(x->this.clearJournalCache(x));
|
||||
parentIdSet.stream().parallel().forEach(x->this.clearParentCache(x));
|
||||
}
|
||||
|
||||
private void clearJournalCache(String journalId) {
|
||||
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_HOT+"_"+journalId);
|
||||
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_NEW+"_"+journalId);
|
||||
// System.out.println("journalId——————"+journalId);
|
||||
}
|
||||
|
||||
private void clearParentCache(String parentId) {
|
||||
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN+"_"+parentId);
|
||||
// System.out.println("parentId_____"+parentId);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue