Commit 255c1823b73ef8e3519e4abba82116f643c24e70
1 parent
97e9f0cc
feature(*): 添加缓存
- 添加缓存
Showing
3 changed files
with
6 additions
and
0 deletions
fw-valhalla-rpc/src/main/java/cn/fw/valhalla/rpc/shirasawa/ShirasawaRpcService.java
... | ... | @@ -13,6 +13,7 @@ import cn.fw.valhalla.rpc.shirasawa.dto.FollowInitDTO; |
13 | 13 | import lombok.RequiredArgsConstructor; |
14 | 14 | import lombok.extern.slf4j.Slf4j; |
15 | 15 | import org.springframework.beans.BeanUtils; |
16 | +import org.springframework.cache.annotation.Cacheable; | |
16 | 17 | import org.springframework.stereotype.Service; |
17 | 18 | |
18 | 19 | import java.time.LocalDate; |
... | ... | @@ -124,6 +125,7 @@ public class ShirasawaRpcService { |
124 | 125 | * @param userId |
125 | 126 | * @return |
126 | 127 | */ |
128 | + @Cacheable(cacheNames = "rpc:user:follow-todo:count", key = "#userId", condition = "#result!=null") | |
127 | 129 | public Boolean hasOngoingFollow(Long userId) { |
128 | 130 | try { |
129 | 131 | if (Objects.isNull(userId)) { | ... | ... |
fw-valhalla-server/src/main/resources/application.yml
fw-valhalla-service/src/main/java/cn/fw/valhalla/component/consumer/FollowResultConsumer.java
... | ... | @@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j; |
12 | 12 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; |
13 | 13 | import org.apache.rocketmq.spring.core.RocketMQListener; |
14 | 14 | import org.springframework.beans.factory.annotation.Autowired; |
15 | +import org.springframework.cache.annotation.CacheEvict; | |
15 | 16 | import org.springframework.stereotype.Component; |
16 | 17 | |
17 | 18 | import java.util.HashSet; |
... | ... | @@ -45,6 +46,7 @@ public class FollowResultConsumer implements RocketMQListener<FollowResultDTO> { |
45 | 46 | } |
46 | 47 | |
47 | 48 | @Override |
49 | + @CacheEvict(cacheNames = "rpc:user:follow-todo:count", key = "#dto.userId") | |
48 | 50 | public void onMessage(FollowResultDTO dto) { |
49 | 51 | log.info("处理跟进结果MQ消息:{}", JSONObject.toJSONString(dto)); |
50 | 52 | try { | ... | ... |