Android 绕过okHttp缓存以获取网络响应,然后更新缓存
我正在使用Refught2和OKHttp缓存HTTP响应。 这是我的密码:Android 绕过okHttp缓存以获取网络响应,然后更新缓存,android,http,retrofit,okhttp,http-caching,Android,Http,Retrofit,Okhttp,Http Caching,我正在使用Refught2和OKHttp缓存HTTP响应。 这是我的密码: int cacheSize = 10 * 1024 * 1024; Cache cache = new Cache(application.getCacheDir(), cacheSize); HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggin
int cacheSize = 10 * 1024 * 1024;
Cache cache = new Cache(application.getCacheDir(), cacheSize);
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().
cache(cache).addNetworkInterceptor(interceptor).build();
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl(mBaseUrl)
.client(okHttpClient)
.build();
我正在从我们的后端RESTAPI获取响应头缓存控制和过期
现在我想通过绕过Expires头来获得服务器响应。
请帮助我解决此问题。将此标头添加到HTTP请求中:
Cache-Control: no-cache
您可以使用改型的
@Header
或OkHttp来完成此操作。每当我需要刷新数据时,我都会调用服务器,但刷新的数据也应该缓存到下次,直到我想要刷新数据为止。