You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Novice User <no...@gmail.com> on 2020/02/27 22:01:48 UTC

Control behavior of Caching based on response

Hi,

We’re using HTTPClient 4.5.11 with caching enabled to make HTTP GET calls to our provider.

The provider returns JSON object and as JSON can miss some keys in some cases, we want to treat it as bad data and avoid it being cached.

There does not seem to be any hook for us to intercept the response body and inspect it and prevent it from being cached.

It seems HTTP Client has HttpCacheInvalidator but it would not work on GET requests, and also I would like something to avoid storing it in cache in first place if response is bad, rather than doing a post processing of invalidation.

Does HTTP client has any ability for us to intercept the response body before it could be saved in cache? 

Thanks,
Akash

Re: Control behavior of Caching based on response

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2020-02-27 at 14:01 -0800, Novice User wrote:
> Hi,
> 
> We’re using HTTPClient 4.5.11 with caching enabled to make HTTP GET
> calls to our provider.
> 
> The provider returns JSON object and as JSON can miss some keys in
> some cases, we want to treat it as bad data and avoid it being
> cached.
> 
> There does not seem to be any hook for us to intercept the response
> body and inspect it and prevent it from being cached.
> 
> It seems HTTP Client has HttpCacheInvalidator but it would not work
> on GET requests, and also I would like something to avoid storing it
> in cache in first place if response is bad, rather than doing a post
> processing of invalidation.
> 
> Does HTTP client has any ability for us to intercept the response
> body before it could be saved in cache? 
> 
> Thanks,
> Akash

You could subclass CachingHttpClientBuilder, override #decorateMainExec
method and insert an extra interceptor between MainExec and
CachingExec.

Oleg 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org