当前位置: 首页>>代码示例>>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;未经允许,请勿转载。