@Override
@Cacheable("stu")
public EmployeeEntity getEmployee(Integer id) {
return employeeDAO.findById(id).get();
} 上面的代码以redis格式将键保存为"stu::7“,此处"stu”是缓存的名称,7是键,但它将缓存名称和id存储为一个键。
但是我想以这种格式存储在redis STU ->7 Stu中,应该是缓存的名称和里面的所有键值对。
发布于 2019-01-29 23:26:10
您可以将自定义密钥生成器设置为@Cacheable注释,可以根据需要自定义它:https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/cache/annotation/Cacheable.html#keyGenerator--。
@Cacheable(value = "stu", keyGenerator = "customKeyGenerator")其中customKeyGenerator是自定义密钥生成器bean的名称。
发布于 2019-01-29 14:04:17
很奇怪,因为医生告诉我
默认值为"",意思是所有方法参数都被视为键,除非已经配置了自定义的keyGenerator()。
这是微不足道的,但是如果您之前不尝试,请尝试显式地设置键和缓存名。
@Cacheable(value = "stu", key = "{#id}")
public EmployeeEntity getEmployee(Integer id) {
return employeeDAO.findById(id).get();
} https://stackoverflow.com/questions/54420829
复制相似问题