问题描述
今天在项目中突然碰到一个问题:使用的缓存是Spring Cache + Caffeine,缓存在执行两次后,突然Key中定义的条件失效。代码如下:
public class CodeOutputService {
// 注入当前类的对象
@Resources
private CodeOutputService codeOutputService;
/**
* 获取所有Leader的信息,如果返回list不为空,则加入缓存
*/
@Cacheable(cacheNames = {"code_output"}, key = "#root.methodName", unless = "#result == null || #result.size() <= 0")
public List<String> getLeaderListOfCode() {
List<String> resultList = new ArrayList<>();
// 此处省略处理逻辑
...
return resultList;
}
/**
* 获取满足条件的Leader的信息,如果返回list不为空,则加入缓存
*/
@Cacheable(cacheNames = {"code_output"}, key = "methodName + T(String).valueOf(#showBoss)", unless = "#result == null || #result.size() <= 0")
public List<String> getLeaderListOfCode(boolean showBoss)
// 如果缓存存在,这里会从缓存中获取
List<String> allLeaderList = this.codeOutputService.getLeade



被折叠的 条评论
为什么被折叠?



