【发布时间】:2021-02-21 09:01:08
【问题描述】:
在 Spring Boot 中我可以在哪些位置使用 @Cacheable 和 redis 缓存, 我可以用任何方法使用它吗?
public UserDTO findByUserID(Long userID) {
User user = findUser(userID);
if (user != null) {
Password password = findPassword(userID);
return userMapper.mapToDTO(user, password);
}
return null;
}
private Password findPassword(Long userID) {
Password password = passwordRepository.findPasswordBasedOnUserID(userID);
return password;
}
@Cacheable("users")
private User findUser(Long userID) {
User user = userRepository.findByUserID(userID);
return user;
}
我已经将它与方法 findUser 一起使用,因为 findByUserID 返回的 DTO 显然不是一个实体,所以为了摆脱它,我创建了两个返回域的方法,但 问题是它没有保存或使用 redis缓存,谁能建议我这个问题或任何解决方案?
【问题讨论】:
标签: spring-boot caching redis redis-cache