I'm using Spring cache and trying to evict cache by a list of key(id).
@CacheEvict(value="cacheName",key=?, condition=? )
public void deleteByIds(List<Integer> ids){...}
How can I manage to do that?
I'm using Spring cache and trying to evict cache by a list of key(id).
@CacheEvict(value="cacheName",key=?, condition=? )
public void deleteByIds(List<Integer> ids){...}
How can I manage to do that?
@CacheEvict
Annotation indicating that a method (or all methods on a class) triggers a cache evict operation.
Names of the caches in which method invocation results are stored.
Expression used for making the method caching conditional.
root.method, root.target, and root.caches for references to the method, target object, and affected cache(s) respectively.
Solution for your problem: Assuming that every object from the List it is cached into, for example cacheName = "entities" and for the key you can use the entity ID (which is the String representation of the Integer value) you should write a second method to evict the cache.
public void deleteByIds(List<Intiger> intigers){
for(Intigier i : intigers){
deleteEntity(i.toString());
}
}
@CacheEvict(cacheName = "entities", key="entityId", condition="entityId!=null")
private void deleteEntity(String entityId){
//processing : for ex delete from the database and also remove from cache
}