本文整理汇总了Java中okhttp3.internal.http.HttpMethod.invalidatesCache方法的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod.invalidatesCache方法的具体用法?Java HttpMethod.invalidatesCache怎么用?Java HttpMethod.invalidatesCache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类okhttp3.internal.http.HttpMethod
的用法示例。
在下文中一共展示了HttpMethod.invalidatesCache方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: maybeCache
import okhttp3.internal.http.HttpMethod; //导入方法依赖的package包/类
private CacheRequest maybeCache(Response userResponse, Request networkRequest,
InternalCache responseCache) throws IOException {
if (responseCache == null) return null;
// Should we cache this response for this request?
if (!CacheStrategy.isCacheable(userResponse, networkRequest)) {
if (HttpMethod.invalidatesCache(networkRequest.method())) {
try {
responseCache.remove(networkRequest);
} catch (IOException ignored) {
// The cache cannot be written.
}
}
return null;
}
// Offer this request to the cache.
return responseCache.put(userResponse);
}
示例2: maybeCache
import okhttp3.internal.http.HttpMethod; //导入方法依赖的package包/类
private CacheRequest maybeCache(Response userResponse, Request networkRequest,
InternalCache responseCache) throws IOException {
if (responseCache == null) return null;
// Should we cache this response for this request?
if (!CacheStrategy.isCacheable(userResponse, networkRequest)) {
//根据请求方式判断是否需要缓存
if (HttpMethod.invalidatesCache(networkRequest.method())) {
try {
responseCache.remove(networkRequest);
} catch (IOException ignored) {
// The cache cannot be written.
}
}
return null;
}
// Offer this request to the cache.
return responseCache.put(userResponse);
}
示例3: execute
import okhttp3.internal.http.HttpMethod; //导入方法依赖的package包/类
protected Response execute(Request request) throws IOException {
if (Http.sCache != null) {
if (HttpMethod.invalidatesCache(request.method())) {
try {
Http.sCache.remove(getUrl());
} catch (IOException ignore) {
}
}
if (!"GET".equals(request.method())) {
setShouldCache(false);
}
}
OkHttpClient client = getClient();
Call call = client.newCall(request);
long start = System.currentTimeMillis();
Response response = call.execute();
if (LOG.isLoggable(Log.INFO))
LOG.i("Took " + (System.currentTimeMillis() - start) + "ms to execute request (" + getLogKey() + ")");
if (Http.sCache != null && HttpHeaders.hasVaryAll(response)) {
setShouldCache(false);
}
return response;
}
示例4: intercept
import okhttp3.internal.http.HttpMethod; //导入方法依赖的package包/类
@Override
public Response intercept(@NonNull final Chain chain) throws IOException {
Request request = chain.request();
// Verify that the HTTP method is for loading data only and doesn't have any side-effects,
// and that the request doesn't contain the 'only-if-cached' Cache-Control directive to
// force loading from the cache.
if (!HttpMethod.invalidatesCache(request.method()) &&
!request.cacheControl().onlyIfCached()) {
// If the request already has the 'stale-if-error' Cache-Control directive, then proceed
// the request chain without interference.
for (final String cacheControlValue : request.headers("Cache-Control")) {
if (PATTERN_STALE_IF_ERROR.matcher(cacheControlValue).matches()) {
return chain.proceed(request);
}
}
// Otherwise add a 'stale-if-error' Cache-Control directive, with the maximum stale
// value set to a very high value.
request = request.newBuilder()
.addHeader("Cache-Control", "stale-if-error=" + Integer.MAX_VALUE)
.build();
}
return chain.proceed(request);
}
示例5: put
import okhttp3.internal.http.HttpMethod; //导入方法依赖的package包/类
CacheRequest put(Response response) {
String requestMethod = response.request().method();
if (HttpMethod.invalidatesCache(response.request().method())) {
try {
remove(response.request());
} catch (IOException ignored) {
// The cache cannot be written.
}
return null;
}
if (!requestMethod.equals("GET")) {
// Don't cache non-GET responses. We're technically allowed to cache
// HEAD requests and some POST requests, but the complexity of doing
// so is high and the benefit is low.
return null;
}
if (HttpHeaders.hasVaryAll(response)) {
return null;
}
Entry entry = new Entry(response);
DiskLruCache.Editor editor = null;
try {
editor = cache.edit(key(response.request().url()));
if (editor == null) {
return null;
}
entry.writeTo(editor);
return new CacheRequestImpl(editor);
} catch (IOException e) {
abortQuietly(editor);
return null;
}
}
示例6: put
import okhttp3.internal.http.HttpMethod; //导入方法依赖的package包/类
@Nullable CacheRequest put(Response response) {
String requestMethod = response.request().method();
if (HttpMethod.invalidatesCache(response.request().method())) {
try {
remove(response.request());
} catch (IOException ignored) {
// The cache cannot be written.
}
return null;
}
if (!requestMethod.equals("GET")) {
// Don't cache non-GET responses. We're technically allowed to cache
// HEAD requests and some POST requests, but the complexity of doing
// so is high and the benefit is low.
return null;
}
if (HttpHeaders.hasVaryAll(response)) {
return null;
}
Entry entry = new Entry(response);
DiskLruCache.Editor editor = null;
try {
editor = cache.edit(key(response.request().url()));
if (editor == null) {
return null;
}
entry.writeTo(editor);
return new CacheRequestImpl(editor);
} catch (IOException e) {
abortQuietly(editor);
return null;
}
}
示例7: put
import okhttp3.internal.http.HttpMethod; //导入方法依赖的package包/类
private CacheRequest put(Response response) throws IOException {
String requestMethod = response.request().method();
if (HttpMethod.invalidatesCache(response.request().method())) {
try {
remove(response.request());
} catch (IOException ignored) {
// The cache cannot be written.
}
return null;
}
if (!requestMethod.equals("GET")) {
// Don't cache non-GET responses. We're technically allowed to cache
// HEAD requests and some POST requests, but the complexity of doing
// so is high and the benefit is low.
return null;
}
if (OkHeaders.hasVaryAll(response)) {
return null;
}
Entry entry = new Entry(response);
DiskLruCache.Editor editor = null;
try {
editor = cache.edit(urlToKey(response.request()));
if (editor == null) {
return null;
}
entry.writeTo(editor);
return new CacheRequestImpl(editor);
} catch (IOException e) {
abortQuietly(editor);
return null;
}
}
示例8: put
import okhttp3.internal.http.HttpMethod; //导入方法依赖的package包/类
private CacheRequest put(Response response) {
String requestMethod = response.request().method();
if (HttpMethod.invalidatesCache(response.request().method())) {
try {
remove(response.request());
} catch (IOException ignored) {
// The cache cannot be written.
}
return null;
}
if (!requestMethod.equals("GET")) {
// Don't cache non-GET responses. We're technically allowed to cache
// HEAD requests and some POST requests, but the complexity of doing
// so is high and the benefit is low.
return null;
}
if (HttpHeaders.hasVaryAll(response)) {
return null;
}
Entry entry = new Entry(response);
DiskLruCache.Editor editor = null;
try {
editor = cache.edit(urlToKey(response.request()));
if (editor == null) {
return null;
}
entry.writeTo(editor);
return new CacheRequestImpl(editor);
} catch (IOException e) {
abortQuietly(editor);
return null;
}
}