title: How to access cache values in Spring
body: <p>Scenario: I need to access the values of a cache created as part of one method in another method. How do I do it?</p>
  <pre><code>public class Invoice {
    private String invoiced;
    private BigDecimal amount;
    //Getters and Setters
  }
  </code></pre>
  <p>Method 1: Gets invoked when a customer wants to get list of invoices from UI</p>
  <pre><code>@Cacheable(value=&quot;invoices&quot;)
  public List&lt;Invoice&gt; getAllInvoices(String customerId){
  ...
  //Get all invoices from Database and return 
  ...
  return invoices
  }
  </code></pre>
  <p>Method 2: Gets invoked when a customer clicks on download on UI</p>
  <pre><code>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 &quot;invoices&quot; here.
   ...
   //if InvoiceId is present in cache then download from db else throw Exception
   return file;
  }
  </code></pre>
  <p>Note: I am not using any caching libraries</p>