diff --git a/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/Services.java b/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/Services.java index 5e93a5dbf..5ad64aad1 100644 --- a/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/Services.java +++ b/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/Services.java @@ -93,6 +93,18 @@ public CoordinatorChannelProvider load(Set key) { } }); + private static final LoadingCache, CoordinatorChannelProvider> utilCache = CacheBuilder + .newBuilder() + .expireAfterAccess(60, TimeUnit.MINUTES) + .expireAfterWrite(60, TimeUnit.MINUTES) + .maximumSize(8) + .build(new CacheLoader, CoordinatorChannelProvider>() { + @Override + public CoordinatorChannelProvider load(Set key) throws Exception { + return coordinatorServiceChannelProvider(key); + } + }); + private static final LoadingCache, LoadingCache> regionCache = CacheBuilder.newBuilder() .expireAfterAccess(30, TimeUnit.MINUTES) @@ -204,6 +216,14 @@ public static VersionService versionService(Set locations) { ).getService(); } + @SneakyThrows + public static UtilService utilService(Set locations) { + Parameters.notEmpty(locations, "locations"); + return new ServiceCaller<>( + utilCache.get(locations), DEFAULT_RETRY_TIMES, DEFAULT, UtilService.Impl::new + ).getService(); + } + @SneakyThrows public static ChannelProvider regionChannelProvider( Set locations, DingoCommonId tableId, DingoCommonId regionId