Search code examples
androidandroid-volleyretrofitokhttpcache-control

Porting from Volley to Retrofit


I'm planning to port my app from volley to Retrofit. Looks very easy and handy to me. I just wanna know, Retrofit use okhttp, will this explicitly cache the response based on the cache-control header similar to Volley.

In Volley HttpHeaderParser.java will take care of the caching part, similar implementation is there or not ??


Solution

  • Retrofit uses OkHttp or another client you want to use. If you don't specify a client, it will be used the default client. But if you want to use OkHttp because of cache or another feature, like set timeout for example, then you can set this client this way:

    OkHttpClient okHttpClient = new OkHttpClient();
    
    RestAdapter restAdapter = new RestAdapter.Builder()
        .setEndpoint(SERVER_URL)
        .setConverter(new GsonConverter(gson))
        .setClient(new OkClient(okHttpClient))
        .build();
    

    Also, see this question and its answers