本文整理了Java中okhttp3.Request.cacheControl
方法的一些代码示例,展示了Request.cacheControl
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.cacheControl
方法的具体详情如下:
包路径:okhttp3.Request
类名称:Request
方法名:cacheControl
[英]Returns the cache control directives for this response. This is never null, even if this response contains no Cache-Control header.
[中]返回此响应的缓存控制指令。即使此响应不包含缓存控制头,它也永远不会为null。
代码示例来源:origin: square/okhttp
/**
* Returns a strategy to satisfy {@code request} using the a cached response {@code response}.
*/
public CacheStrategy get() {
CacheStrategy candidate = getCandidate();
if (candidate.networkRequest != null && request.cacheControl().onlyIfCached()) {
// We're forbidden from using the network and the cache is insufficient.
return new CacheStrategy(null, null);
}
return candidate;
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
/**
* Returns a strategy to satisfy {@code request} using the a cached response {@code response}.
*/
public CacheStrategy get() {
CacheStrategy candidate = getCandidate();
if (candidate.networkRequest != null && request.cacheControl().onlyIfCached()) {
// We're forbidden from using the network and the cache is insufficient.
return new CacheStrategy(null, null);
}
return candidate;
}
代码示例来源:origin: square/picasso
@Override public void onSuccess(Result result) {
try {
assertThat(requests.takeFirst().cacheControl().toString()).isEmpty();
latch.countDown();
} catch (InterruptedException e) {
throw new AssertionError(e);
}
}
代码示例来源:origin: north2016/T-MVP
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
if (!NetWorkUtil.isNetConnected(App.getAppContext())) {
request = request.newBuilder()
.cacheControl(CacheControl.FORCE_CACHE)
.build();
Log.d("Okhttp", "no network");
}
Response originalResponse = chain.proceed(request);
if (NetWorkUtil.isNetConnected(App.getAppContext())) {
//有网的时候读接口上的@Headers里的配置,你可以在这里进行统一的设置
String cacheControl = request.cacheControl().toString();
return originalResponse.newBuilder()
.header("Cache-Control", cacheControl)
.removeHeader("Pragma")
.build();
} else {
return originalResponse.newBuilder()
.header("Cache-Control", "public, only-if-cached, max-stale=2419200")
.removeHeader("Pragma")
.build();
}
}
}
代码示例来源:origin: jaydenxiao2016/AndroidFire
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
String cacheControl = request.cacheControl().toString();
if (!NetWorkUtils.isNetConnected(BaseApplication.getAppContext())) {
request = request.newBuilder()
.cacheControl(TextUtils.isEmpty(cacheControl)?CacheControl.FORCE_NETWORK:CacheControl.FORCE_CACHE)
.build();
}
Response originalResponse = chain.proceed(request);
if (NetWorkUtils.isNetConnected(BaseApplication.getAppContext())) {
//有网的时候读接口上的@Headers里的配置,你可以在这里进行统一的设置
return originalResponse.newBuilder()
.header("Cache-Control", cacheControl)
.removeHeader("Pragma")
.build();
} else {
return originalResponse.newBuilder()
.header("Cache-Control", "public, only-if-cached, max-stale=" + CACHE_STALE_SEC)
.removeHeader("Pragma")
.build();
}
}
};
代码示例来源:origin: Rukey7/MvpApp
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
if (!NetUtil.isNetworkAvailable(AndroidApplication.getContext())) {
request = request.newBuilder().cacheControl(CacheControl.FORCE_CACHE).build();
Logger.e("no network");
}
Response originalResponse = chain.proceed(request);
if (NetUtil.isNetworkAvailable(AndroidApplication.getContext())) {
//有网的时候读接口上的@Headers里的配置,你可以在这里进行统一的设置
String cacheControl = request.cacheControl().toString();
return originalResponse.newBuilder()
.header("Cache-Control", cacheControl)
.removeHeader("Pragma")
.build();
} else {
return originalResponse.newBuilder()
.header("Cache-Control", "public, " + CACHE_CONTROL_CACHE)
.removeHeader("Pragma")
.build();
}
}
};
代码示例来源:origin: square/okhttp
return !response.cacheControl().noStore() && !request.cacheControl().noStore();
代码示例来源:origin: square/okhttp
CacheControl requestCaching = request.cacheControl();
if (requestCaching.noCache() || hasConditions(request)) {
return new CacheStrategy(request, null);
代码示例来源:origin: com.squareup.okhttp3/okhttp
return !response.cacheControl().noStore() && !request.cacheControl().noStore();
代码示例来源:origin: com.squareup.okhttp3/okhttp
CacheControl requestCaching = request.cacheControl();
if (requestCaching.noCache() || hasConditions(request)) {
return new CacheStrategy(request, null);
代码示例来源:origin: square/picasso
@Test public void withZeroRetryCountForcesLocalCacheOnly() throws Exception {
responses.add(responseOf(ResponseBody.create(null, new byte[10])));
Action action = TestUtils.mockAction(URI_KEY_1, URI_1);
PlatformLruCache cache = new PlatformLruCache(0);
BitmapHunter hunter =
new BitmapHunter(picasso, dispatcher, cache, stats, action, networkHandler);
hunter.retryCount = 0;
hunter.hunt();
assertThat(requests.takeFirst().cacheControl().toString()).isEqualTo(CacheControl.FORCE_CACHE.toString());
}
代码示例来源:origin: kaku2015/ColorfulNews
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
if (!NetUtil.isNetworkAvailable()) {
request = request.newBuilder()
.cacheControl(CacheControl.FORCE_CACHE)
.build();
KLog.d("no network");
}
Response originalResponse = chain.proceed(request);
if (NetUtil.isNetworkAvailable()) {
//有网的时候读接口上的@Headers里的配置,你可以在这里进行统一的设置
String cacheControl = request.cacheControl().toString();
return originalResponse.newBuilder()
.header("Cache-Control", cacheControl)
.removeHeader("Pragma")
.build();
} else {
return originalResponse.newBuilder()
.header("Cache-Control", "public, only-if-cached, max-stale=" + CACHE_STALE_SEC)
.removeHeader("Pragma")
.build();
}
}
};
代码示例来源:origin: lionoggo/FastApp
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = chain.proceed(request);
String cacheControl = request.cacheControl().toString();
if (TextUtils.isEmpty(cacheControl)) {
cacheControl = "public,max-age=60";
}
return response.newBuilder().header("Cache-Control", cacheControl).build();
}
代码示例来源:origin: lionoggo/Akit-Reader
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = chain.proceed(request);
String cacheControl = request.cacheControl().toString();
if (TextUtils.isEmpty(cacheControl)) {
cacheControl = "public,max-age=60";
}
return response.newBuilder().header("Cache-Control", cacheControl).build();
}
代码示例来源:origin: charbgr/SeismicInterceptor
private Map<String, List<String>> generateBasicInfo() {
Map<String, List<String>> info = new LinkedHashMap<>();
info.put("URL", Arrays.asList(request.url().toString()));
info.put("VERB", Arrays.asList(request.method()));
if (responseExceptionWrapper.isResponse())
info.put("Status", Arrays.asList(String.valueOf(responseExceptionWrapper.getResponse().code())));
if (request.cacheControl() != null)
info.put("Cache-Request", Arrays.asList(request.cacheControl().toString()));
if (responseExceptionWrapper.isResponse() && responseExceptionWrapper.getResponse().cacheControl() != null)
info.put("Cache-Response", Arrays.asList(responseExceptionWrapper.getResponse().cacheControl().toString()));
return info;
}
代码示例来源:origin: duzechao/OKHttpUtils
/**
* Returns a strategy to satisfy {@code request} using the a cached response {@code response}.
*/
public CacheStrategy get() {
CacheStrategy candidate = getCandidate();
if (candidate.networkRequest != null && request.cacheControl().onlyIfCached()) {
// We're forbidden from using the network and the cache is insufficient.
return new CacheStrategy(null, null);
}
return candidate;
}
代码示例来源:origin: com.github.ljun20160606/okhttp
/**
* Returns a strategy to satisfy {@code request} using the a cached response {@code response}.
*/
public CacheStrategy get() {
CacheStrategy candidate = getCandidate();
if (candidate.networkRequest != null && request.cacheControl().onlyIfCached()) {
// We're forbidden from using the network and the cache is insufficient.
return new CacheStrategy(null, null);
}
return candidate;
}
代码示例来源:origin: huxq17/SwipeCardsView
/**
* Returns a strategy to satisfy {@code request} using the a cached response
* {@code response}.
*/
public CacheStrategy get() {
CacheStrategy candidate = getCandidate();
if (candidate.networkRequest != null && request.cacheControl().onlyIfCached()) {
// We're forbidden from using the network and the cache is insufficient.
return new CacheStrategy(null, null);
}
return candidate;
}
代码示例来源:origin: huxq17/tractor
/**
* Returns a strategy to satisfy {@code request} using the a cached response
* {@code response}.
*/
public CacheStrategy get() {
CacheStrategy candidate = getCandidate();
if (candidate.networkRequest != null && request.cacheControl().onlyIfCached()) {
// We're forbidden from using the network and the cache is insufficient.
return new CacheStrategy(null, null);
}
return candidate;
}
代码示例来源:origin: apache/servicemix-bundles
/**
* Returns a strategy to satisfy {@code request} using the a cached response {@code response}.
*/
public CacheStrategy get() {
CacheStrategy candidate = getCandidate();
if (candidate.networkRequest != null && request.cacheControl().onlyIfCached()) {
// We're forbidden from using the network and the cache is insufficient.
return new CacheStrategy(null, null);
}
return candidate;
}
内容来源于网络,如有侵权,请联系作者删除!