Reputation: 5226
In example, I have a webapp that shows recommended movies to each user. Service's method does an API call to another platform and returns movies. I have to implement following logic:
User requests his movies recommendations. If the API call was successfull, put it in the cache and return. Otherwise not (if the method returned null). But user also may press refresh button. In this case, evict cache for that user, do API call and put it in cache again. How can I force refresh the cache?
Upvotes: 1
Views: 14278
Reputation: 3024
You can add condition
parameter of @Cacheable
.
If the evaluated value is false
, the method will be invoked.
Upvotes: 3
Reputation: 33101
There's a @CacheEvict
annotation that you can use on the method that triggers a "refresh". Check the documentation for more details
Upvotes: 0