Apache CachingConfig对我不起作用?

时间:2018-07-12 07:44:03

标签: java apache-httpclient-4.x

我将CloseableHttpclient与Cachconfig一起使用,如下所示:

RequestConfig defaultRequestConfig = RequestConfig.custom()
            .setConnectTimeout(2000)
            .setSocketTimeout(2000)
            .setConnectionRequestTimeout(2000)
            .build();
CacheConfig cacheConfig = CacheConfig.custom()
             .setMaxCacheEntries(3000)
             .setMaxObjectSize(1024*100)
             .build();
CloseableHttpClient cachingClient = CachingHttpClients.custom()
             .setCacheConfig(cacheConfig)
             .setDefaultReqeustConfig(defaultRequestConfig)
             .build();

但是缓存不起作用???并且没有响应被缓存。

private int executeRequest(HttpGet httpGet)
{
    HttpCacheContext context = HttpCacheContext.create();
   // for example : httpGet = new HttpGet("http://example/main.js");
   CloseableHttpResponse response = cachingClient.execute(httpGet, context);
   if(context .getCacheResponseStatuss == CacheRespopnseStatus.CACHE_HIT)
      {
          log.info("read response from cache");
       }
...
}

0 个答案:

没有答案