java - 如何在 @CacheEvict#key 的 SpEL 中获取#root.args[0] 的字段
问题描述
@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
调用方法后,springboot:demo:cache:{id}
从方法生成的query
仍然存在于缓存(Redis)中。我应该怎么做才能准确地驱逐它?非常感谢。
解决方案
推荐阅读
- c - 我的 memcpy 函数意外打印 src 两次
- javascript - 通过直接拖放 woff 文件来更改页面的字体
- angular - 角度中的 FormControl 和 AbstractControl 问题
- java - 将方法标记为返回现有的可关闭对象,以避免在使用站点出现虚假警告
- tensorflow - 为什么输入与层model_16不兼容?
- javascript - 如何制作一个按钮,按下时按钮会消失并弹出一个新的div
- python - vs代码终端说python 2.7,但我选择了3.8
- command - 如何从Stata的数据集中删除特定的观察结果?
- r - 如何使 klaR 的 greedy.wilks 函数在后 HCPC 数据帧上工作?
- javascript - 背景图像不适用于 Chrome for Mac 上的一个 div