public static final Interceptor REWRITE_RESPONSE_INTERCEPTOR = new Interceptor() { @Override public okhttp3.Response intercept(Chain chain) throws IOException { okhttp3.Response originalResponse = chain.proceed(chain.request()); String cacheControl = originalResponse.header("Cache-Control"); if (cacheControl == null || cacheControl.contains("no-store") || cacheControl.contains("no-cache") || cacheControl.contains("must-revalidate") || cacheControl.contains("max-age=0")) { int max_age=60*5; return originalResponse.newBuilder() .removeHeader("Pragma") .header("Cache-Control", "public, max-age=" + max_age) .build(); } else { return originalResponse; } } }; public static Interceptor REWRITE_RESPONSE_INTERCEPTOR_OFFLINE = new Interceptor() { @Override public okhttp3.Response intercept(Chain chain) throws IOException { Request request = chain.request(); if (!NetworkUtils.isConnected()) { // int maxStale = 60 * 60 * 24 * 28; // request = request.newBuilder() // .removeHeader("Pragma") // .header("Cache-Control", "public, only-if-cached,max-stale=" + maxStale) // .build(); request = request.newBuilder() .removeHeader("Pragma") .cacheControl(CacheControl.FORCE_CACHE) .build(); } return chain.proceed(request); } };