I developed a method that use @Cacheable annotation. The code is:
@Cacheable(value="reporties" , key="{#root.methodName,#manager.name}")
public List<Employee> getReportiesForManager(Employee manager){
// code to fetch reporties its a Spring JDBC call
}
Now, I want to evict this cache after some events:
- Some reporties related with manager have been updated (added or removed).
After that, the cache related with the manager should be evicted, in that way, the application will get new data instead of using the existing one in that cache. I developed the following method for that:
@CacheEvict(value="reporties",key="{#name}")
public void evictReportiesCache(String name){}
I call inside the method which updates the relations of the Manager and its reporties. However, this one works intermittently and I am not sure if that's the correct way to evict cache. Also the Cacheable uses #root.methodName as part of key.
Can someone please help me with this cache eviction?