// Tries to get head and body from cache, return true if has got this time
 // or
 // already got before
 private boolean getFromCache() throws IOException {
   if (useCaches && null != responseCache && !hasTriedCache) {
     hasTriedCache = true;
     if (null == resHeader) {
       resHeader = new Header();
     }
     cacheResponse = responseCache.get(uri, method, resHeader.getFieldMap());
     if (null != cacheResponse) {
       Map<String, List<String>> headMap = cacheResponse.getHeaders();
       if (null != headMap) {
         resHeader = new Header(headMap);
       }
       is = cacheResponse.getBody();
       if (null != is) {
         return true;
       }
     }
   }
   if (hasTriedCache && null != is) {
     return true;
   }
   return false;
 }
 @Override
 public CacheResponse get(URI uri, String requestMethod, Map<String, List<String>> requestHeaders)
     throws IOException {
   return responseCache.get(uri, requestMethod, requestHeaders);
 }
示例#3
0
 /**
  * Returns the {@link CacheResponse} from the delegate by converting the OkHttp {@link Request}
  * into the arguments required by the {@link ResponseCache}.
  */
 private CacheResponse getJavaCachedResponse(Request request) throws IOException {
   Map<String, List<String>> headers = JavaApiConverter.extractJavaHeaders(request);
   return delegate.get(request.url().uri(), request.method(), headers);
 }