Last active
May 28, 2020 14:45
-
-
Save shikto1/d6d00139ff82e4e8d4ed79e9d2f2c73b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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