How do I create an async caching http client?

此生再无相见时 提交于 2019-12-04 07:04:37

问题


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.

e.g.

CloseableHttpClient client = CachingHttpClientBuilder.create()
    .setCacheConfig(cacheConfig())
    .build();

CloseableHttpAsyncClient build = HttpAsyncClientBuilder.create()
    .build();

Por que no los dos?

N.B. I'm not tied to this version of the library - happy for solutions using the latest version.

Related:

  • How do I implement client side http caching like a browser?

回答1:


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.



来源:https://stackoverflow.com/questions/43623608/how-do-i-create-an-async-caching-http-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!