Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cachingHttpclient cannot ignore header "Cache-Control: no-cache"

I am using Apache cachingHttpClient to query a REST API from java code.

I want to cache some http response despite receiving "Cache-Control: no-cache" header which cause the cachingHttpClient to not cache the file.

With standalone http proxy such as squid,mod_cache..., I could tweak the configuration to ignore those headers and overide default behaviour.

I'd rather not go for standalone http proxy but rather go for 100% java code.

  1. is there another http client that would offer more control on caching ?
  2. can I implement an intermediate layer/proxy that would rewrite the headers ?
  3. can I patch cachingHttpClient through inheritance ?
like image 252
Frederic Bazin Avatar asked Aug 13 '26 13:08

Frederic Bazin


1 Answers

The request is being rejected by the CachedResponseSuitabilityChecker in the canCachedResponseBeUsed method. If you need different behavior, that's the class to implement your own version of, and then use the long constructor for cachingHttpClient

CachingHttpClient(HttpClient backend, 
     CacheValidityPolicy validityPolicy,
     ResponseCachingPolicy responseCachingPolicy,
     HttpCache responseCache,
     CachedHttpResponseGenerator responseGenerator,
     CacheableRequestPolicy cacheableRequestPolicy,
     CachedResponseSuitabilityChecker suitabilityChecker, 
     ConditionalRequestBuilder conditionalRequestBuilder, 
     ResponseProtocolCompliance responseCompliance, 
     RequestProtocolCompliance requestCompliance) 
like image 72
evil otto Avatar answered Aug 15 '26 02:08

evil otto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!