Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 绕过okHttp缓存以获取网络响应,然后更新缓存_Android_Http_Retrofit_Okhttp_Http Caching - Fatal编程技术网

Android 绕过okHttp缓存以获取网络响应,然后更新缓存

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

我正在使用Refught2和OKHttp缓存HTTP响应。 这是我的密码:

    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来完成此操作。

每当我需要刷新数据时,我都会调用服务器,但刷新的数据也应该缓存到下次,直到我想要刷新数据为止。