I am using the retrofit 2 and OkHttp3 to request data from server. I just added a offline cache code but It\'s not working as expected. I got the error \"Unable to resolve host
Your server response has a "Pragma: no-cache" header. You should remove this header in your response interceptor not your request interceptor.
In your current code you've removed it from the request interceptor.
Your provideCacheInterceptor()
should look like this:
public static Interceptor provideCacheInterceptor() {
return new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Response response = chain.proceed(chain.request());
// re-write response header to force use of cache
CacheControl cacheControl = new CacheControl.Builder()
.maxAge(2, TimeUnit.MINUTES)
.build();
return response.newBuilder()
.header(CACHE_CONTROL, cacheControl.toString())
.removeHeader("Pragma")
.build();
}
};
}