【发布时间】:2016-10-26 07:11:26
【问题描述】:
我有一个用例,我希望能够根据对象的属性缓存方法的结果。该属性是私有的,但公开了一个公共吸气剂。 (这可以改变,但我不想这样做)
@Cacheable(cacheNames = "detailedData", key = "#id", condition = "#currentPackage.getSellingPrice() > -1")
public Map<String, Object> getDetailedTestData(int id,PackageEntity currentPackage) {
/**
some code
*/
}
PackageEntity 类是
public class PackageEntity {
private int sellingPrice;
public int getSellingPrice() {
return sellingPrice;
}
public void setSellingPrice(int sellingPrice) {
this.sellingPrice = sellingPrice;
}
/**
some other fields and their getter/setter
*/
}
条件缓存的 Spring doc 指定了如何使用条件。但是,这种 cahcing 并不像条件所指示的那样工作。无论售价如何,它只是缓存所有包裹。 我无法理解我做错了什么。也没有合适的例子可以参考。
任何帮助表示赞赏。谢谢
【问题讨论】:
标签: java spring annotations ehcache spring-cache