Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save shikto1/98977449f929f1d742e4bc9b98dd926d to your computer and use it in GitHub Desktop.
static Interceptor onlineInterceptor = new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
okhttp3.Response response = chain.proceed(chain.request());
int maxAge = 60; // read from cache for 60 seconds even if there is internet connection
return response.newBuilder()
.header("Cache-Control", "public, max-age=" + maxAge)
.removeHeader("Pragma")
.build();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment