RestTemplate不考虑Apache http客户端提供的cacheConfig

时间:2018-04-13 12:04:33

标签: spring rest apache-httpclient-4.x

示例代码:

final CacheConfig cacheConfig = CacheConfig.custom()
  .setMaxCacheEntries(50)
  .setMaxObjectSize(800)
  .setHeuristicCachingEnabled(true)
  .setHeuristicDefaultLifetime(5)
  .build();

final CloseableHttpClient httpClient = CachingHttpClients.custom()
  .setCacheConfig(cacheConfig)
  .build();

final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
final RestTemplate restTemplate = new RestTemplate(factory);
restClient.getForObject("serverUri"); //this is never hitting the cache.

看起来像apacheHttpClient从未调用过?

0 个答案:

没有答案