【发布时间】:2015-07-13 12:51:58
【问题描述】:
我想尝试 Volley 与 OkHttp 的结合,但 Volley 缓存系统和 OkHttp 都依赖于 HTTP 规范中定义的 HTTP 缓存。那么如何禁用 OkHttp 的缓存来保留一份 HTTP 缓存呢?
编辑:我做了什么
public class VolleyUtil {
// http://arnab.ch/blog/2013/08/asynchronous-http-requests-in-android-using-volley/
private volatile static RequestQueue sRequestQueue;
/** get the single instance of RequestQueue **/
public static RequestQueue getQueue(Context context) {
if (sRequestQueue == null) {
synchronized (VolleyUtil.class) {
if (sRequestQueue == null) {
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new StethoInterceptor());
client.setCache(null);
sRequestQueue = Volley.newRequestQueue(context.getApplicationContext(), new OkHttpStack(client));
VolleyLog.DEBUG = true;
}
}
}
return sRequestQueue;
}
}
哪个OkHttpClient引用自https://gist.github.com/bryanstern/4e8f1cb5a8e14c202750
【问题讨论】:
-
你能告诉我们你做了什么
-
@Soham 感谢您的回复,我重新编辑了我的问题,谢谢。
标签: android caching android-volley okhttp