Kong / unirest-java

Unirest in Java: Simplified, lightweight HTTP client library.
http://kong.github.io/unirest-java/
MIT License
2.6k stars 592 forks source link

Add support for caching #325

Closed Mulgish closed 4 years ago

Mulgish commented 4 years ago

Is your feature request related to a problem? Please describe. I would like to be able to easily setup http caching in Unirest.

Describe the solution you'd like Unirest.config().cacheConfig()

Describe alternatives you've considered Manual setup which did not seem to work as there is no way to set cache context on Unirest call.

HttpCacheContext context = HttpCacheContext.create();
HttpGet httpget = new HttpGet("http://www.mydomain.com/content/");
CloseableHttpResponse response = cachingClient.execute(httpget, context);
 final CacheConfig cacheConfig = CacheConfig.custom()
                .setMaxCacheEntries(1000)
                .setMaxObjectSize(8192)
                .build();
        final RequestConfig requestConfig = RequestConfig.custom()
                .setConnectTimeout(30000)
                .setSocketTimeout(30000)
                .build();
        final CloseableHttpClient cachingClient = CachingHttpClients.custom()
                .setCacheConfig(cacheConfig)
                .setDefaultRequestConfig(requestConfig)
                .build();
        Unirest.config()
                .httpClient(ApacheClient.builder(cachingClient));
ryber commented 4 years ago

Now that I (and everyone else) is stuck at home for a while I figure I would get moving on this.

I don't want to just use Apache's cache because one of the goals of this project is to get off of Apache as a dependency. So I'm going to do my own caching layer. I'll try and split it up and do something simple and then add some more options. Here is what I was thinking:

MVP Features:

Advanced Features:

Any other thoughts are appreciated.

ryber commented 4 years ago

Complete in 3.8.00 see http://kong.github.io/unirest-java/#caching