/** * Returns true if computeFreshnessLifetime used a heuristic. If we used a heuristic to serve a * cached response older than 24 hours, we are required to attach a warning. */ private boolean isFreshnessLifetimeHeuristic() { return cacheResponse.cacheControl().maxAgeSeconds() == -1 && expires == null; }
/** * Returns true if computeFreshnessLifetime used a heuristic. If we used a heuristic to serve a * cached response older than 24 hours, we are required to attach a warning. */ private boolean isFreshnessLifetimeHeuristic() { return cacheResponse.cacheControl().maxAgeSeconds() == -1 && expires == null; }
/** * Returns the number of milliseconds that the response was fresh for, starting from the served * date. */ private long computeFreshnessLifetime() { CacheControl responseCaching = cacheResponse.cacheControl(); if (responseCaching.maxAgeSeconds() != -1) { return SECONDS.toMillis(responseCaching.maxAgeSeconds()); } else if (expires != null) { long servedMillis = servedDate != null ? servedDate.getTime() : receivedResponseMillis; long delta = expires.getTime() - servedMillis; return delta > 0 ? delta : 0; } else if (lastModified != null && cacheResponse.request().url().query() == null) { // As recommended by the HTTP RFC and implemented in Firefox, the // max age of a document should be defaulted to 10% of the // document's age at the time it was served. Default expiration // dates aren't used for URIs containing a query. long servedMillis = servedDate != null ? servedDate.getTime() : sentRequestMillis; long delta = servedMillis - lastModified.getTime(); return delta > 0 ? (delta / 10) : 0; } return 0; }
|| response.cacheControl().maxAgeSeconds() != -1 || response.cacheControl().isPublic() || response.cacheControl().isPrivate()) { break; return !response.cacheControl().noStore() && !request.cacheControl().noStore();
/** * Returns the number of milliseconds that the response was fresh for, starting from the served * date. */ private long computeFreshnessLifetime() { CacheControl responseCaching = cacheResponse.cacheControl(); if (responseCaching.maxAgeSeconds() != -1) { return SECONDS.toMillis(responseCaching.maxAgeSeconds()); } else if (expires != null) { long servedMillis = servedDate != null ? servedDate.getTime() : receivedResponseMillis; long delta = expires.getTime() - servedMillis; return delta > 0 ? delta : 0; } else if (lastModified != null && cacheResponse.request().url().query() == null) { // As recommended by the HTTP RFC and implemented in Firefox, the // max age of a document should be defaulted to 10% of the // document's age at the time it was served. Default expiration // dates aren't used for URIs containing a query. long servedMillis = servedDate != null ? servedDate.getTime() : sentRequestMillis; long delta = servedMillis - lastModified.getTime(); return delta > 0 ? (delta / 10) : 0; } return 0; }
|| response.cacheControl().maxAgeSeconds() != -1 || response.cacheControl().isPublic() || response.cacheControl().isPrivate()) { break; return !response.cacheControl().noStore() && !request.cacheControl().noStore();
CacheControl responseCaching = cacheResponse.cacheControl();
CacheControl responseCaching = cacheResponse.cacheControl();
// Add Cache-Control to origin response (force cache) client.networkInterceptors().add(new Interceptor() { private com.squareup.okhttp.Request request; private Response response; private String requestUrl; @Override public Response intercept(Chain c) throws IOException { request = c.request(); response = c.proceed(request); if (!request.cacheControl().noStore() && !response.cacheControl().noStore()) { requestUrl = request.urlString(); // Do not cache keys or playlists response = response .newBuilder() .header("Cache-Control","public, max-age=42000").build(); } return response; } });
/** * Returns true if computeFreshnessLifetime used a heuristic. If we used a * heuristic to serve a cached response older than 24 hours, we are required * to attach a warning. */ private boolean isFreshnessLifetimeHeuristic() { return cacheResponse.cacheControl().maxAgeSeconds() == -1 && expires == null; }
/** * Returns true if computeFreshnessLifetime used a heuristic. If we used a * heuristic to serve a cached response older than 24 hours, we are required * to attach a warning. */ private boolean isFreshnessLifetimeHeuristic() { return cacheResponse.cacheControl().maxAgeSeconds() == -1 && expires == null; }
/** * Returns true if computeFreshnessLifetime used a heuristic. If we used a heuristic to serve a * cached response older than 24 hours, we are required to attach a warning. */ private boolean isFreshnessLifetimeHeuristic() { return cacheResponse.cacheControl().maxAgeSeconds() == -1 && expires == null; }
/** * Returns true if computeFreshnessLifetime used a heuristic. If we used a heuristic to serve a * cached response older than 24 hours, we are required to attach a warning. */ private boolean isFreshnessLifetimeHeuristic() { return cacheResponse.cacheControl().maxAgeSeconds() == -1 && expires == null; }
/** * Returns true if computeFreshnessLifetime used a heuristic. If we used a heuristic to serve a * cached response older than 24 hours, we are required to attach a warning. */ private boolean isFreshnessLifetimeHeuristic() { return cacheResponse.cacheControl().maxAgeSeconds() == -1 && expires == null; }
@Override public void onResponse(Call call, Response response) throws IOException { Log.e(TAG, "onResponse: body==" + response.body().string()); Log.e(TAG, "onResponse: netResponse==" + response.networkResponse()); Log.e(TAG, "onResponse: cacheResponse==" + response.cacheResponse()); Log.e(TAG, "onResponse: cacheControl==" + response.cacheControl().toString()); Log.e(TAG, "onResponse: threadName==" + Thread.currentThread().getName()); } });
@Override public void onResponse(Call call, Response response) throws IOException { Log.e(TAG, "onResponse1: body==" + response.body().string()); Log.e(TAG, "onResponse1: netResponse==" + response.networkResponse()); Log.e(TAG, "onResponse1: cacheResponse==" + response.cacheResponse()); Log.e(TAG, "onResponse1: cacheControl==" + response.cacheControl().toString()); Log.e(TAG, "onResponse1: threadName==" + Thread.currentThread().getName()); } });
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; }
/** * Returns the number of milliseconds that the response was fresh for, * starting from the served date. */ private long computeFreshnessLifetime() { CacheControl responseCaching = cacheResponse.cacheControl(); if (responseCaching.maxAgeSeconds() != -1) { return SECONDS.toMillis(responseCaching.maxAgeSeconds()); } else if (expires != null) { long servedMillis = servedDate != null ? servedDate.getTime() : receivedResponseMillis; long delta = expires.getTime() - servedMillis; return delta > 0 ? delta : 0; } else if (lastModified != null && cacheResponse.request().url().query() == null) { // As recommended by the HTTP RFC and implemented in Firefox, the // max age of a document should be defaulted to 10% of the // document's age at the time it was served. Default expiration // dates aren't used for URIs containing a query. long servedMillis = servedDate != null ? servedDate.getTime() : sentRequestMillis; long delta = servedMillis - lastModified.getTime(); return delta > 0 ? (delta / 10) : 0; } return 0; }
/** * Returns the number of milliseconds that the response was fresh for, * starting from the served date. */ private long computeFreshnessLifetime() { CacheControl responseCaching = cacheResponse.cacheControl(); if (responseCaching.maxAgeSeconds() != -1) { return SECONDS.toMillis(responseCaching.maxAgeSeconds()); } else if (expires != null) { long servedMillis = servedDate != null ? servedDate.getTime() : receivedResponseMillis; long delta = expires.getTime() - servedMillis; return delta > 0 ? delta : 0; } else if (lastModified != null && cacheResponse.request().url().query() == null) { // As recommended by the HTTP RFC and implemented in Firefox, the // max age of a document should be defaulted to 10% of the // document's age at the time it was served. Default expiration // dates aren't used for URIs containing a query. long servedMillis = servedDate != null ? servedDate.getTime() : sentRequestMillis; long delta = servedMillis - lastModified.getTime(); return delta > 0 ? (delta / 10) : 0; } return 0; }
NetworkInterceptor implements Interceptor { public static final String DEBUG_TAG = NetworkInterceptor.class.getSimpleName(); @Override public Response intercept(Chain chain) throws IOException { Request request=chain.request(); User user=UserHandler.getUser(); if (user!=null&&user.getToken()!=null){ Log.d(DEBUG_TAG,"Authorization: "+user.getToken()); request=request.newBuilder().addHeader("Authorization",user.getToken()) // Only if the response is stored .addHeader("Cache-Control", "only-if-cached") // Return cached responses not older than 2419200 seconds (28 days) //.addHeader("Cache-Control", "max-stale=2419200") .method(request.method(),request.body()) .build(); } Response response = chain.proceed(request); Log.d(DEBUG_TAG, "Cache-Control: " + response.cacheControl()); return response; } }