我使用 retrofit和 okhttp在我们的一个应用程序中。
对于 Retrofit 的默认行为,我真的找不到很好的解释。
如果 Okhttp 在类路径上,它将被自动使用。但据我所知,默认的 HttpResponseCache 为空。
我是否需要使用 Retrofit 和 Okhttp 显式启用缓存?
最佳答案
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();
关于android - Retrofit+Okhttp 是否在 Android 中默认使用 httpCaching?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21577159/