eghe
eghe

Reputation: 167

How to delete an entry in a cache

I am using Spring cache. I would like to delete a single entry within the cache if a particular condition is met in due time.

   @Cacheable(value = "statusEligibility", key = "#customerId")
   @GetMapping
   public CustomerStatusDTO getCustomerStatus(@PathVariable String customerId) {

  Customer customer = cusomterPort.getAccount(customerId);
  Status status = service.getStatus(customer);

  //Logic:
  //If status equals required then forward call to service to assert it. then delete the account from cache
  //else return not_required
  if (status.equals(Cons.REQUIRED)) {
     /.../
  } else {
     /.../
  }

}

How would I be able to delete the customer object from the cache if it fulfils the condition in the if statement?

Upvotes: 0

Views: 2441

Answers (1)

Related Questions