缓存热点数据, 缩短调用链
适用于强一致性
@Service public class UserService{ @Autowired private UserDAO userDAO; private RedisTemplate redisTemplate; public User getUserById(Integer id) { User user = redisTemplate.opForObject(); if (user == null) { user = userDAO.getUserById(id); if (user != null) { redisTemplate.update(); } } } public void updateUser(User user) { Integer id = user.getId(); userDAO.updateUser(user); redisTemplate.delete(id); } }