Skip to content

Instantly share code, notes, and snippets.

@shikto1
Last active May 28, 2020 14:45
Show Gist options
  • Select an option

  • Save shikto1/d6d00139ff82e4e8d4ed79e9d2f2c73b to your computer and use it in GitHub Desktop.

Select an option

Save shikto1/d6d00139ff82e4e8d4ed79e9d2f2c73b to your computer and use it in GitHub Desktop.
static Interceptor offlineInterceptor= new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
if (!isInternetAvailable()) {
int maxStale = 60 * 60 * 24 * 30; // Offline cache available for 30 days
request = request.newBuilder()
.header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
.removeHeader("Pragma")
.build();
}
return chain.proceed(request);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment