当前位置: 首页>>代码示例>>Java>>正文


Java CacheControl.minFreshSeconds方法代码示例

本文整理汇总了Java中com.squareup.okhttp.CacheControl.minFreshSeconds方法的典型用法代码示例。如果您正苦于以下问题:Java CacheControl.minFreshSeconds方法的具体用法?Java CacheControl.minFreshSeconds怎么用?Java CacheControl.minFreshSeconds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.squareup.okhttp.CacheControl的用法示例。


在下文中一共展示了CacheControl.minFreshSeconds方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCandidate

import com.squareup.okhttp.CacheControl; //导入方法依赖的package包/类
private CacheStrategy getCandidate() {
    if (this.cacheResponse == null) {
        return new CacheStrategy(this.request, null, null);
    }
    if (this.request.isHttps() && this.cacheResponse.handshake() == null) {
        return new CacheStrategy(this.request, null, null);
    }
    if (!CacheStrategy.isCacheable(this.cacheResponse, this.request)) {
        return new CacheStrategy(this.request, null, null);
    }
    CacheControl requestCaching = this.request.cacheControl();
    if (requestCaching.noCache() || hasConditions(this.request)) {
        return new CacheStrategy(this.request, null, null);
    }
    long ageMillis = cacheResponseAge();
    long freshMillis = computeFreshnessLifetime();
    if (requestCaching.maxAgeSeconds() != -1) {
        freshMillis = Math.min(freshMillis, TimeUnit.SECONDS.toMillis((long) requestCaching
                .maxAgeSeconds()));
    }
    long minFreshMillis = 0;
    if (requestCaching.minFreshSeconds() != -1) {
        minFreshMillis = TimeUnit.SECONDS.toMillis((long) requestCaching.minFreshSeconds());
    }
    long maxStaleMillis = 0;
    CacheControl responseCaching = this.cacheResponse.cacheControl();
    if (!(responseCaching.mustRevalidate() || requestCaching.maxStaleSeconds() == -1)) {
        maxStaleMillis = TimeUnit.SECONDS.toMillis((long) requestCaching.maxStaleSeconds());
    }
    if (responseCaching.noCache() || ageMillis + minFreshMillis >= freshMillis +
            maxStaleMillis) {
        Builder conditionalRequestBuilder = this.request.newBuilder();
        if (this.etag != null) {
            conditionalRequestBuilder.header("If-None-Match", this.etag);
        } else if (this.lastModified != null) {
            conditionalRequestBuilder.header("If-Modified-Since", this.lastModifiedString);
        } else if (this.servedDate != null) {
            conditionalRequestBuilder.header("If-Modified-Since", this.servedDateString);
        }
        Request conditionalRequest = conditionalRequestBuilder.build();
        if (hasConditions(conditionalRequest)) {
            return new CacheStrategy(conditionalRequest, this.cacheResponse, null);
        }
        return new CacheStrategy(conditionalRequest, null, null);
    }
    Response$Builder builder = this.cacheResponse.newBuilder();
    if (ageMillis + minFreshMillis >= freshMillis) {
        builder.addHeader("Warning", "110 HttpURLConnection \"Response is stale\"");
    }
    if (ageMillis > a.h && isFreshnessLifetimeHeuristic()) {
        builder.addHeader("Warning", "113 HttpURLConnection \"Heuristic expiration\"");
    }
    return new CacheStrategy(null, builder.build(), null);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:55,代码来源:CacheStrategy$Factory.java

示例2: getCandidate

import com.squareup.okhttp.CacheControl; //导入方法依赖的package包/类
/** Returns a strategy to use assuming the request can use the network. */
private CacheStrategy getCandidate() {
  // No cached response.
  if (cacheResponse == null) {
    return new CacheStrategy(request, null);
  }

  // Drop the cached response if it's missing a required handshake.
  if (request.isHttps() && cacheResponse.handshake() == null) {
    return new CacheStrategy(request, null);
  }

  // If this response shouldn't have been stored, it should never be used
  // as a response source. This check should be redundant as long as the
  // persistence store is well-behaved and the rules are constant.
  if (!isCacheable(cacheResponse, request)) {
    return new CacheStrategy(request, null);
  }

  CacheControl requestCaching = request.cacheControl();
  if (requestCaching.noCache() || hasConditions(request)) {
    return new CacheStrategy(request, null);
  }

  long ageMillis = cacheResponseAge();
  long freshMillis = computeFreshnessLifetime();

  if (requestCaching.maxAgeSeconds() != -1) {
    freshMillis = Math.min(freshMillis, SECONDS.toMillis(requestCaching.maxAgeSeconds()));
  }

  long minFreshMillis = 0;
  if (requestCaching.minFreshSeconds() != -1) {
    minFreshMillis = SECONDS.toMillis(requestCaching.minFreshSeconds());
  }

  long maxStaleMillis = 0;
  CacheControl responseCaching = cacheResponse.cacheControl();
  if (!responseCaching.mustRevalidate() && requestCaching.maxStaleSeconds() != -1) {
    maxStaleMillis = SECONDS.toMillis(requestCaching.maxStaleSeconds());
  }

  if (!responseCaching.noCache() && ageMillis + minFreshMillis < freshMillis + maxStaleMillis) {
    Response.Builder builder = cacheResponse.newBuilder();
    if (ageMillis + minFreshMillis >= freshMillis) {
      builder.addHeader("Warning", "110 HttpURLConnection \"Response is stale\"");
    }
    long oneDayMillis = 24 * 60 * 60 * 1000L;
    if (ageMillis > oneDayMillis && isFreshnessLifetimeHeuristic()) {
      builder.addHeader("Warning", "113 HttpURLConnection \"Heuristic expiration\"");
    }
    return new CacheStrategy(null, builder.build());
  }

  Request.Builder conditionalRequestBuilder = request.newBuilder();

  if (lastModified != null) {
    conditionalRequestBuilder.header("If-Modified-Since", lastModifiedString);
  } else if (servedDate != null) {
    conditionalRequestBuilder.header("If-Modified-Since", servedDateString);
  }

  if (etag != null) {
    conditionalRequestBuilder.header("If-None-Match", etag);
  }

  Request conditionalRequest = conditionalRequestBuilder.build();
  return hasConditions(conditionalRequest)
      ? new CacheStrategy(conditionalRequest, cacheResponse)
      : new CacheStrategy(conditionalRequest, null);
}
 
开发者ID:NannanZ,项目名称:spdymcsclient,代码行数:72,代码来源:CacheStrategy.java

示例3: getCandidate

import com.squareup.okhttp.CacheControl; //导入方法依赖的package包/类
/** Returns a strategy to use assuming the request can use the network. */
private CacheStrategy getCandidate() {
  // No cached response.
  if (cacheResponse == null) {
    return new CacheStrategy(request, null, ResponseSource.NETWORK);
  }

  // Drop the cached response if it's missing a required handshake.
  if (request.isHttps() && cacheResponse.handshake() == null) {
    return new CacheStrategy(request, null, ResponseSource.NETWORK);
  }

  // If this response shouldn't have been stored, it should never be used
  // as a response source. This check should be redundant as long as the
  // persistence store is well-behaved and the rules are constant.
  if (!isCacheable(cacheResponse, request)) {
    return new CacheStrategy(request, null, ResponseSource.NETWORK);
  }

  CacheControl requestCaching = request.cacheControl();
  if (requestCaching.noCache() || hasConditions(request)) {
    return new CacheStrategy(request, cacheResponse, ResponseSource.NETWORK);
  }

  long ageMillis = cacheResponseAge();
  long freshMillis = computeFreshnessLifetime();

  if (requestCaching.maxAgeSeconds() != -1) {
    freshMillis = Math.min(freshMillis, SECONDS.toMillis(requestCaching.maxAgeSeconds()));
  }

  long minFreshMillis = 0;
  if (requestCaching.minFreshSeconds() != -1) {
    minFreshMillis = SECONDS.toMillis(requestCaching.minFreshSeconds());
  }

  long maxStaleMillis = 0;
  CacheControl responseCaching = cacheResponse.cacheControl();
  if (!responseCaching.mustRevalidate() && requestCaching.maxStaleSeconds() != -1) {
    maxStaleMillis = SECONDS.toMillis(requestCaching.maxStaleSeconds());
  }

  if (!responseCaching.noCache() && ageMillis + minFreshMillis < freshMillis + maxStaleMillis) {
    Response.Builder builder = cacheResponse.newBuilder()
        .setResponseSource(ResponseSource.CACHE); // Overwrite any stored response source.
    if (ageMillis + minFreshMillis >= freshMillis) {
      builder.addHeader("Warning", "110 HttpURLConnection \"Response is stale\"");
    }
    long oneDayMillis = 24 * 60 * 60 * 1000L;
    if (ageMillis > oneDayMillis && isFreshnessLifetimeHeuristic()) {
      builder.addHeader("Warning", "113 HttpURLConnection \"Heuristic expiration\"");
    }
    return new CacheStrategy(null, builder.build(), ResponseSource.CACHE);
  }

  Request.Builder conditionalRequestBuilder = request.newBuilder();

  if (lastModified != null) {
    conditionalRequestBuilder.header("If-Modified-Since", lastModifiedString);
  } else if (servedDate != null) {
    conditionalRequestBuilder.header("If-Modified-Since", servedDateString);
  }

  if (etag != null) {
    conditionalRequestBuilder.header("If-None-Match", etag);
  }

  Request conditionalRequest = conditionalRequestBuilder.build();
  return hasConditions(conditionalRequest)
      ? new CacheStrategy(conditionalRequest, cacheResponse, ResponseSource.CONDITIONAL_CACHE)
      : new CacheStrategy(conditionalRequest, null, ResponseSource.NETWORK);
}
 
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:73,代码来源:CacheStrategy.java


注:本文中的com.squareup.okhttp.CacheControl.minFreshSeconds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。