@Service
public class UserService {
private final User[] database = new User[]{new User(0, "foo")};
@Cacheable(cacheNames = "springboot:demo:cache", key = "#root.args[0]")
public User query(Integer id) {
return database[0];
}
@CacheEvict(cacheNames = "springboot:demo:cache", key = "#root.args[0].id")
public void update(User user) {
database[0] = user;
}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User implements Serializable {
private static final long serialVersionUID = -1760350679406802739L;
Integer id;
String name;
}
我希望的效果:update 方法被执行后,之前由于 query 缓存在缓存里的(我用的是 redis )键被清除,但实际上并没有。。。
谢谢