本文整理汇总了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);
}
示例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);
}
示例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);
}