We have refactored some parts of our application, and after that, methods annotated with spring cachable stopped being cached although the class containing the cached method was not touched.
After some debugging, we can see that after refactoring and adding some new Spring beans, the bean with the cachable method is now created in the same batch as the internalCacheAdvisor itself. The Advice can thus not be applied and the Spring cache aspect is never invoked. So the method result is not cached, @Cachable annotation does not work.
What mechanism is deciding what beans that can be created simultaneously, and how can I debug and affect this mechanism?
I have looked in the Spring method BeanFactoryAdvisorRetrievalHelper::findAdvisorBeans, and when running the old and worikng code, it looks like this:
After refactoring it looks like this:
Our annotated class couchbaseTranslationProvider is created at the same batch as internalCacheAdvisor, which is not possible. When trying to apply the advice proxy, I get a debug message "Skipping currently created advisor ...". (I think this should have been an error message!)
Our POM-file enabling the cache looks like this:
@Configuration
@EnableWebMvc
@ComponentScan({"[package]", "[package].connectors"})
@Import({EventsConfig.class,
CmsConfig.class})
@EnableCaching
public class ApiConfig {
public static class Caches{
public static final String SPORTS = "sports";
[...]
public static final String PIPEDTRANSLATIONS = "translations";
}
@Value("${[package].document}")
private String someUrl;
@Bean
public CouchbaseClient getCouchbaseClient() throws IOException {
[code]
}
@Bean
public CacheManager cacheManager() {
SimpleCacheManager cacheManager = new SimpleCacheManager();
cacheManager.setCaches(Arrays.asList(new ConcurrentMapCache(Caches.SPORTS),
[...],
new ConcurrentMapCache(Caches.PIPEDTRANSLATIONS)));
return cacheManager;
}
@Autowired
private EventUpdateGate eventUpdateGate;
@Bean
@ConditionalOnProperty("AdapterGate.events.active")
public AdapterGateReceiver eventAdapterGateReceiver(@Value("${AdapterGate.events.gateChannel}") String channel,
@Value("${AdapterGate.events.apiVersion}") String version) {
return new AdapterGateReceiver(channel, version, eventUpdateGate);
}
}