我在UserService中有一个方法:
@Cacheable(value="user", key="#p0")
public User find(String name) {
return userRepository.findOneByName(name);
}
它缓存了。但后来我尝试从“用户”中获取所有密钥。缓存:
CacheManager cacheManager = CacheManager.getInstance();
cacheManager.getCache("user").getKeys().forEach(o -> log.debug(o.toString()));
输出:
com.cache.domain.User#1
相反,例如,' John Doe'。
答案 0 :(得分:0)
请参阅getKeys
返回缓存中所有元素的列表,无论它们是否已过期。
实际上是返回元素,没有id。您可能希望更改代码以将o
投射到Element
并输出getObjectKey()
。
您无需指定key
属性。因为你想要的是使用你的方法的单个参数(name
),默认情况下缓存抽象将使用它。