如何创建异步缓存的HTTP客户端? [英] How do I create an async caching http client?
问题描述
使用 org.apache.httpcomponents:httpasyncclient-cache:4.1.3
库,我试图弄清楚如何创建异步
缓存
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();
没有问题吗?
NB 我不依赖于此版本的库-对于使用最新版本的解决方案感到满意。
N.B. I'm not tied to this version of the library - happy for solutions using the latest version.
相关:
- How do I implement client side http caching like a browser?
推荐答案
在构建 HttpAsyncClient $ c $之后,您可以直接创建一个新的
CachingHttpAsyncClient
c>。例如:
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());
您可以从此处。
这篇关于如何创建异步缓存的HTTP客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!