[英]Condition on cacheable annotation on private property of Object
我有一個用例,我希望能夠根據對象的屬性緩存方法的結果。 該物業是私人的,但暴露了公共吸氣劑。 (這可以改變,但我不想這樣做)
@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指定了如何使用條件。 但是,這種情況並不適用於條件。 無論銷售價格如何,它都可以簡單地緩存所有包裹。 我無法理解我做錯了什么。 我沒有合適的例子可以參考。
任何幫助贊賞。 謝謝
如果指定的字段是私有的,SpEL似乎也會查找該字段的公共getter。
因此,該領域可以是公共的,也可以是公共吸氣劑
@Cacheable(cacheNames = "detailedData", key = "#id", condition ="#currentPackage.sellingPrice > -1")
public Map<String, Object> getDetailedTestData(int id,PackageEntity currentPackage) {
/**
some code
*/
}
所以上面的代碼對我來說沒問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.