Spring 缓存逐出

Spring Cache Eviction

我有两个服务

class CustomerService {
   public void removeCustomer(int customerId) {...}
}

class OrderService {
   @Cacheable("orders")
   public List<Order> getOrders() {...}
}

removeCustomer() 我希望 orders 缓存被驱逐,因为结果已经改变(被移除的客户的订单已经消失)。我如何使用 Spring 的缓存来做到这一点?

您可以使用@CacheEvict 注释。详情请参考以下link

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/cache/annotation/CacheEvict.html

您可以在

找到示例

https://dzone.com/articles/spring-31-caching-and-0