1

I have two services

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

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

On removeCustomer() I want the orders cache to be evicted, since the result has changed (the orders of the removed customers are gone). How can I do this with Spring's caching?

1 Answer 1

1

You can use @CacheEvict annotation for the same. Please refer to the below link for details

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

You can find example at

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.