被改造+ Okhttp使用httpCaching作为Android的默认? [英] Is Retrofit+Okhttp using httpCaching as a default in Android?

查看:155
本文介绍了被改造+ Okhttp使用httpCaching作为Android的默认?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用改造 okhttp 在我们的应用程序之一。

I use retrofit and okhttp in one of our applications.

我真的不能找到一个很好的解释了改造的默认行为。

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

如果Okhttp是在类路径上它会自动使用。但据我可以看到它默认的Htt presponseCache为空。

If Okhttp is on the class path it will be automatically used. But as far as I can see it the default HttpResponseCache is null.

我是否需要明确启用缓存与改造和Okhttp?

Do I need to explicitly enable caching with Retrofit and Okhttp?

推荐答案

您应该手动创建OkHttpClient并配置它,你怎么样。在这种情况下,你应该安装一个高速缓存。一旦你有创建一个 OkClient ,并把它传递给改造的< A HREF =htt​​p://square.github.io/retrofit/javadoc/retrofit/RestAdapter.html相对=nofollow> RestAdapter.Builder

You should manually create your OkHttpClient and configure it how you like. In this case you should install a cache. Once you have that create an OkClient and pass it to Retrofit's RestAdapter.Builder

此外,没有缓存的HTTP POST请求。获取将被缓存,但是。

Also, no caching for HTTP POST requests. GETs will be cached, however.

这篇关于被改造+ Okhttp使用httpCaching作为Android的默认?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆