1

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:

Community
  • 1
  • 1
Nick Grealy
  • 24,216
  • 9
  • 104
  • 119

1 Answers1

3

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.

Nick Grealy
  • 24,216
  • 9
  • 104
  • 119
Ke Li
  • 942
  • 6
  • 12