Is Retrofit+Okhttp using httpCaching as a default in Android?

前端 未结 3 897
悲&欢浪女
悲&欢浪女 2020-12-28 11:25

I use retrofit and okhttp in one of our applications.

I can\'t really find a good explanation for the default behaviour of Retrofit.

If Okhttp is on the cl

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-28 11:54

    Correct implementation for OkHttpClient v2:

    int cacheSize = 10 * 1024 * 1024; // 10 MiB
    File cacheDir = new File(context.getCacheDir(), "HttpCache");
    Cache cache = new Cache(cacheDir, cacheSize);
    OkHttpClient client = new OkHttpClient.Builder()
        .cache(cache)
        .build();
    

    see documentation

提交回复
热议问题