Spring Cache Eviction

时间:2017-09-05 20:45:35

标签: spring caching spring-4 spring-cache

我有两项服务

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

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

开启removeCustomer()我想要驱逐orders缓存,因为结果已经改变(移除的客户的订单消失了)。我怎么能用Spring的缓存来做到这一点?

1 个答案:

答案 0 :(得分:1)

您可以使用@CacheEvict注释。有关详细信息,请参阅以下链接

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

您可以在

找到示例

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