@Test void getUserInfo() { UserInfo userInfo = userService.getUserInfo("xiaoming"); log.info("user info: {}", userInfo); }
@Override @Cacheable("getUserInfo") public UserInfo getUserInfo(String key) { UserInfo userInfo = redisTemplate.opsForValue().get(key); if (userInfo == null) { log.info("cache null : {}", key); userInfo = addUser("demo","demo"); } return userInfo; }
UserServiceImpl implements UserService { @Override @Cacheable("getUserInfo") public UserInfo getUserInfo(String key) { UserInfo userInfo = redisTemplate.opsForValue().get(key); if (userInfo == null) { log.info("cache null : {}", key); userInfo = addUser("demo","demo"); } return userInfo; } }
UserServiceImpl implements UserService { @Override @Cacheable("getUserInfo") public UserInfo getUserInfo(String key) { UserInfo userInfo = redisTemplate.opsForValue().get(key); if (userInfo == null) { log.info("cache null : {}", key); userInfo = addUser("demo","demo"); } return userInfo; } @Autowired  UserServiceImpl(RedisTemplate<String, UserInfo> redisTemplate); }
UserServiceImpl implements UserService { @Override @Cacheable("getUserInfo") public UserInfo getUserInfo(String key) { UserInfo userInfo = redisTemplate.opsForValue().get(key); if (userInfo == null) { log.info("cache null : {}", key); userInfo = addUser("demo","demo"); } return userInfo; } @Autowired  UserServiceImpl(RedisTemplate<String, UserInfo> redisTemplate); @Override @Cacheable("getUserInfo") UserInfo getUserInfo(String key); @Override @Cacheable("userinfo") UserInfo addUser(String username, String password); @Override UserInfo updateUsername(String id, String username); }
UserServiceImpl implements UserService { @Override @Cacheable("getUserInfo") public UserInfo getUserInfo(String key) { UserInfo userInfo = redisTemplate.opsForValue().get(key); if (userInfo == null) { log.info("cache null : {}", key); userInfo = addUser("demo","demo"); } return userInfo; } @Autowired  UserServiceImpl(RedisTemplate<String, UserInfo> redisTemplate); @Override @Cacheable("getUserInfo") UserInfo getUserInfo(String key); @Override @Cacheable("userinfo") UserInfo addUser(String username, String password); @Override UserInfo updateUsername(String id, String username);  }