场景:我需要在另一种方法中访问作为一种方法的一部分创建的缓存的值。我该怎么做?
public class Invoice {
private String invoiced;
private BigDecimal amount;
//Getters and Setters
}
Run Code Online (Sandbox Code Playgroud)
方法 1:当客户想要从 UI 获取发票列表时调用
@Cacheable(value="invoices")
public List<Invoice> getAllInvoices(String customerId){
...
//Get all invoices from Database and return
...
return invoices
}
Run Code Online (Sandbox Code Playgroud)
方法2:当客户点击UI上的下载时调用
public File downloadInvoice(String invoiceId) {
//TODO:
//Validate if invoiceId is present in the cache. This is a validation step
//How can I access the cache "invoices" here.
...
//if InvoiceId is present in cache then download from db else throw Exception
return file; …Run Code Online (Sandbox Code Playgroud)