I have a use case in which I want to be able to cache the result of a method based on the property of a object. The property is private but exposes a public getter. (This can be changed, but i would not want to do that)
@Cacheable(cacheNames = "detailedData", key = "#id", condition = "#currentPackage.getSellingPrice() > -1")
public Map<String, Object> getDetailedTestData(int id,PackageEntity currentPackage) {
/**
some code
*/
}
PackageEntity
class is
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 for conditional caching specifies how to use condition. However, this cahcing does not works as indicated by condition. It is simply caching all packages irrespective of selling price. I am unable to understand what am I doing wrong. Neither there are suitable examples that I can refer for this.
Any help appreciated. Thanks