Reputation: 5469
I am using Spring's caching facility. When I call the following method, I want to evict the cache for all the values in the array receiptObject.resolverIds
:
@Override
@Caching(evict = {
@CacheEvict(value = "assignedFeedbacks", key = "#receiptObject.resolverIds[0]"),
@CacheEvict(value = "newFeedbacks", key = "#receiptObject.feedbackObject.serviceId") })
public void addReceipt(ReceiptObject receiptObject) throws Exception {
feedbackDao.insertReceipt(receiptObject);
}
Here I have only used the first element but I want to generalize this for all the elements in the array. How do I do it?
Upvotes: 1
Views: 502
Reputation: 121202
I guess that you have somewhere a @Cacheable
method like this:
@Cacheable(value = "assignedFeedbacks")
public void getReceipt(Object receiptId) throws Exception {
Since @Caching
annotations can get deal only with single cache entry at once, there is no reason to take a look how SpEL can can work with arrays, because the key
should be a single object.
The only way I see is based on the direct Cache Abstraction usage:
@Autowired
private CacheManager cacheManager;
public void addReceipt(ReceiptObject receiptObject) throws Exception {
feedbackDao.insertReceipt(receiptObject);
Cache cache = cacheManager.getCache("assignedFeedbacks");
for (Object receiptId: receiptObject.getResolverIds()) {
cache.evict(receiptId);
}
}
Upvotes: 1