當前位置: 首頁>>代碼示例>>Java>>正文


Java OkResponseCache.trackConditionalCacheHit方法代碼示例

本文整理匯總了Java中com.squareup.okhttp.OkResponseCache.trackConditionalCacheHit方法的典型用法代碼示例。如果您正苦於以下問題:Java OkResponseCache.trackConditionalCacheHit方法的具體用法?Java OkResponseCache.trackConditionalCacheHit怎麽用?Java OkResponseCache.trackConditionalCacheHit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.squareup.okhttp.OkResponseCache的用法示例。


在下文中一共展示了OkResponseCache.trackConditionalCacheHit方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readResponse

import com.squareup.okhttp.OkResponseCache; //導入方法依賴的package包/類
/**
 * Flushes the remaining request header and body, parses the HTTP response
 * headers and starts reading the HTTP response body if it exists.
 */
public final void readResponse() throws IOException {
  if (hasResponse()) {
    responseHeaders.setResponseSource(responseSource);
    return;
  }

  if (responseSource == null) {
    throw new IllegalStateException("readResponse() without sendRequest()");
  }

  if (!responseSource.requiresConnection()) {
    return;
  }

  if (sentRequestMillis == -1) {
    if (requestBodyOut instanceof RetryableOutputStream) {
      int contentLength = ((RetryableOutputStream) requestBodyOut).contentLength();
      requestHeaders.setContentLength(contentLength);
    }
    transport.writeRequestHeaders();
  }

  if (requestBodyOut != null) {
    requestBodyOut.close();
    if (requestBodyOut instanceof RetryableOutputStream) {
      transport.writeRequestBody((RetryableOutputStream) requestBodyOut);
    }
  }

  transport.flushRequest();

  responseHeaders = transport.readResponseHeaders();
  responseHeaders.setLocalTimestamps(sentRequestMillis, System.currentTimeMillis());
  responseHeaders.setResponseSource(responseSource);

  if (responseSource == ResponseSource.CONDITIONAL_CACHE) {
    if (cachedResponseHeaders.validate(responseHeaders)) {
      release(false);
      ResponseHeaders combinedHeaders = cachedResponseHeaders.combine(responseHeaders);
      this.responseHeaders = combinedHeaders;

      // Update the cache after applying the combined headers but before initializing the content
      // stream, otherwise the Content-Encoding header (if present) will be stripped from the
      // combined headers and not end up in the cache file if transparent gzip compression is
      // turned on.
      OkResponseCache responseCache = client.getOkResponseCache();
      responseCache.trackConditionalCacheHit();
      responseCache.update(cacheResponse, policy.getHttpConnectionToCache());

      initContentStream(cachedResponseBody);
      return;
    } else {
      Util.closeQuietly(cachedResponseBody);
    }
  }

  if (hasResponseBody()) {
    maybeCache(); // reentrant. this calls into user code which may call back into this!
  }

  initContentStream(transport.getTransferStream(cacheRequest));
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:67,代碼來源:HttpEngine.java

示例2: readResponse

import com.squareup.okhttp.OkResponseCache; //導入方法依賴的package包/類
/**
 * Flushes the remaining request header and body, parses the HTTP response
 * headers and starts reading the HTTP response body if it exists.
 */
public final void readResponse() throws IOException {
    if (hasResponse()) {
        responseHeaders.setResponseSource(responseSource);
        return;
    }

    if (responseSource == null) {
        throw new IllegalStateException("readResponse() without sendRequest()");
    }

    if (!responseSource.requiresConnection()) {
        return;
    }

    if (sentRequestMillis == -1) {
        if (requestBodyOut instanceof RetryableOutputStream) {
            int contentLength = ((RetryableOutputStream) requestBodyOut).contentLength();
            requestHeaders.setContentLength(contentLength);
        }
        transport.writeRequestHeaders();
    }

    if (requestBodyOut != null) {
        requestBodyOut.close();
        if (requestBodyOut instanceof RetryableOutputStream) {
            transport.writeRequestBody((RetryableOutputStream) requestBodyOut);
        }
    }

    transport.flushRequest();

    responseHeaders = transport.readResponseHeaders();
    responseHeaders.setLocalTimestamps(sentRequestMillis, System.currentTimeMillis());
    responseHeaders.setResponseSource(responseSource);

    if (responseSource == ResponseSource.CONDITIONAL_CACHE) {
        if (cachedResponseHeaders.validate(responseHeaders)) {
            release(false);
            ResponseHeaders combinedHeaders = cachedResponseHeaders.combine(responseHeaders);
            setResponse(combinedHeaders, cachedResponseBody);
            OkResponseCache responseCache = client.getOkResponseCache();
            responseCache.trackConditionalCacheHit();
            responseCache.update(cacheResponse, policy.getHttpConnectionToCache());
            return;
        } else {
            Util.closeQuietly(cachedResponseBody);
        }
    }

    if (hasResponseBody()) {
        maybeCache(); // reentrant. this calls into user code which may call back into this!
    }

    initContentStream(transport.getTransferStream(cacheRequest));
}
 
開發者ID:goodev,項目名稱:android-discourse,代碼行數:60,代碼來源:HttpEngine.java


注:本文中的com.squareup.okhttp.OkResponseCache.trackConditionalCacheHit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。