如何创建异步缓存 http 客户端? [英] How do I create an async caching http client?
问题描述
使用 org.apache.httpcomponents:httpasyncclient-cache:4.1.3
库,我试图找出如何创建 asynchronous
缓存
http客户端?
Using the org.apache.httpcomponents:httpasyncclient-cache:4.1.3
library, I'm trying to work out how I can create an asynchronous
caching
http client?
我可以使用各自的构建器单独创建每个,但我找不到同时拥有两者的方法.
I can create each individually, using their respective builders, but I can't find a way to have both.
CloseableHttpClient client = CachingHttpClientBuilder.create()
.setCacheConfig(cacheConfig())
.build();
<小时>
CloseableHttpAsyncClient build = HttpAsyncClientBuilder.create()
.build();
Por que no los dos?
Por que no los dos?
注意我不依赖于这个版本的库 - 很高兴使用最新版本的解决方案.
N.B. I'm not tied to this version of the library - happy for solutions using the latest version.
相关:
推荐答案
您可以在构建 HttpAsyncClient
后直接创建一个新的 CachingHttpAsyncClient
.例如:
You can create a new CachingHttpAsyncClient
directly after you have built a HttpAsyncClient
. For example:
CloseableHttpAsyncClient asyncClient= HttpAsyncClientBuilder.create().build();
CachingHttpAsyncClient client = new CachingHttpAsyncClient(asyncClient, cacheConfig());
你可以从这里了解更多构造函数.一>.
You can know more constructors from here.
这篇关于如何创建异步缓存 http 客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!