I have a method annotated with @Cacheable. If an exception is captured inside the method, I want the cache to be cleared. However, it seems that the cache is loaded in an aspect that is executed after the line that clears it. Therefore, when an Exception is captured in the method, even though the cache is cleared, the empty string result stays in the cache.
Where should I clear the cache from?
@Cacheable("myCache")
public String myMethod() {
String result="";
try {
result = doSomething();
} catch (Exception e) {
cacheManager.getCache("myCache").clear();
}
return token;
}