oscerd commented on a change in pull request #6728: URL: https://github.com/apache/camel/pull/6728#discussion_r783906955
########## File path: components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/cache/CaffeineCacheEndpoint.java ########## @@ -64,27 +64,37 @@ public Producer createProducer() throws Exception { @Override protected void doStart() throws Exception { - cache = CamelContextHelper.lookup(getCamelContext(), cacheName, Cache.class); - if (cache == null) { - Caffeine<?, ?> builder = Caffeine.newBuilder(); - if (configuration.getEvictionType() == EvictionType.SIZE_BASED) { - builder.initialCapacity(configuration.getInitialCapacity()); - builder.maximumSize(configuration.getMaximumSize()); - } else if (configuration.getEvictionType() == EvictionType.TIME_BASED) { - builder.expireAfterAccess(configuration.getExpireAfterAccessTime(), TimeUnit.SECONDS); - builder.expireAfterWrite(configuration.getExpireAfterWriteTime(), TimeUnit.SECONDS); - } - if (configuration.isStatsEnabled()) { - if (ObjectHelper.isEmpty(configuration.getStatsCounter())) { - builder.recordStats(); + + synchronized (this) { + cache = CamelContextHelper.lookup(getCamelContext(), cacheName, Cache.class); + if (cache == null) { + if (configuration.isCreateCacheIfNotExist()) { + Caffeine<?, ?> builder = Caffeine.newBuilder(); + if (configuration.getEvictionType() == EvictionType.SIZE_BASED) { + builder.initialCapacity(configuration.getInitialCapacity()); + builder.maximumSize(configuration.getMaximumSize()); + } else if (configuration.getEvictionType() == EvictionType.TIME_BASED) { + builder.expireAfterAccess(configuration.getExpireAfterAccessTime(), TimeUnit.SECONDS); + builder.expireAfterWrite(configuration.getExpireAfterWriteTime(), TimeUnit.SECONDS); + } + if (configuration.isStatsEnabled()) { + if (ObjectHelper.isEmpty(configuration.getStatsCounter())) { + builder.recordStats(); + } else { + builder.recordStats(configuration::getStatsCounter); + } + } + if (ObjectHelper.isNotEmpty(configuration.getRemovalListener())) { + builder.removalListener(configuration.getRemovalListener()); + } + cache = builder.build(); + getCamelContext().getRegistry().bind(cacheName, Cache.class, cache); Review comment: Essentialy the cache needs to be created ahead of the enbpoint instantiation and start, so it should be in the registry before. You're, by the way, welcome to test and improve the component :-) Thanks a lot! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org