You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/08/04 03:12:23 UTC

[GitHub] [rocketmq] fuyou001 commented on a diff in pull request #4669: using caffeine replace guava cache

fuyou001 commented on code in PR #4669:
URL: https://github.com/apache/rocketmq/pull/4669#discussion_r937308817


##########
proxy/src/main/java/org/apache/rocketmq/proxy/service/route/TopicRouteService.java:
##########
@@ -64,10 +68,14 @@ public TopicRouteService(MQClientAPIFactory mqClientAPIFactory) {
             config.getTopicRouteServiceThreadPoolQueueCapacity()
         );
         this.mqClientAPIFactory = mqClientAPIFactory;
-        this.topicCache = CacheBuilder.newBuilder()
-            .maximumSize(config.getTopicRouteServiceCacheMaxNum())
-            .refreshAfterWrite(config.getTopicRouteServiceCacheExpiredInSeconds(), TimeUnit.SECONDS)
-            .build(new TopicRouteCacheLoader());
+
+        this.topicCache = Caffeine.newBuilder().maximumSize(config.getTopicRouteServiceCacheMaxNum()).
+            refreshAfterWrite(config.getTopicRouteServiceCacheExpiredInSeconds(), TimeUnit.SECONDS).
+            executor(cacheRefreshExecutor).build(new CacheLoader<String, MessageQueueView>() {
+                @Override public @Nullable MessageQueueView load(String topic) throws Exception {
+                    return topicRouteCacheLoader.load(topic);

Review Comment:
   1. fix
   2. if occur exceptions then return old value,see   https://github.com/ben-manes/caffeine/wiki/Refresh
   



-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org