Retrofit + OkHttp + cache + HTTPS

I have a problem with Retrofit combining with OkHttp Cache and HTTPS. It just doesn't work. When I switch the endpoint to a non-https version everything works.

My Retrofit instance:

File cacheDirectory = new File(App.get().getApplicationContext()
    .getCacheDir().getAbsolutePath(), "HttpCache");

try {
    cache = new Cache(cacheDirectory, 10 * 1024 * 1024);
} catch (IOException ioe) {
    Log.w(TAG, ioe);
}

OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setCache(cache);

mInstance = new RestAdapter.Builder()
    .setLogLevel(RestAdapter.LogLevel.HEADERS)
    .setEndpoint("https://....")
    .setClient(new OkClient(okHttpClient))
    .setConverter(new SimpleXMLConverter())
    .setExecutors(Executors.newSingleThreadExecutor(), new MainThreadExecutor())
    .setRequestInterceptor(new RequestInterceptor() {
        @Override
        public void intercept(RequestFacade request) {
            request.addHeader("Cache-Control", "public, max-age=900");
        }
    })
    .build()
    .create(Restu.class);

      

The response contains the header correctly **Cache-Control: public, max-age=900**

.

+1
android caching https retrofit okhttp


source to share


No one has answered this question yet

See similar questions:

108
Upgradeable using OKHttp data cache when offline
3
Retrofit library with disk cache support

or similar:

1554
Disable Chrome cache for website development
1398
How do we control web page caching in all browsers?
1001
Is Safari iOS 6 caching $ .ajax results?
951
How do I force the browser to reload the cached CSS / JS files?
867
Are URLs encrypted with HTTPS?
559
Android Network Libraries Comparison: OkHTTP, Retrofit and Volleyball
108
Upgradeable using OKHttp data cache when offline
five
Session cookie is unstable on Android update
1
Retrofit: cache control was never included in the response
0
Is it possible to reply to OkHttp cache messages that have authorization in the request header



All Articles
Loading...
X
Show
Funny
Dev
Pics