首页 > 解决方案 > 如何删除缓存中的条目

问题描述

我正在使用 Spring 缓存。如果在适当的时候满足特定条件,我想删除缓存中的单个条目。

   @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 {
     /.../
  }

}

如果满足 if 语句中的条件,我将如何从缓存中删除客户对象?

标签: javaspringspring-cache

解决方案



推荐阅读