Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.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_Caching_Retrofit_Okhttp - Fatal编程技术网

Android OkHttp响应缓存在过期后不工作

Android OkHttp响应缓存在过期后不工作,android,caching,retrofit,okhttp,Android,Caching,Retrofit,Okhttp,我正在使用okHttp缓存http响应,我并没有在服务器端实现任何东西。所以对于缓存,我使用拦截器。我已经将缓存年龄设置为一周。因此,它可以正常工作一周,如果我将设备时间更改为一周以上,那么它将从服务器加载,而不是从缓存中获取,我需要的是在过期后,它应该从服务器获取新响应,并且应该一直保持到缓存过期。我的拦截器如下所示 private class CacheInterceptor implements Interceptor { Context mContext;

我正在使用okHttp缓存http响应,我并没有在服务器端实现任何东西。所以对于缓存,我使用拦截器。我已经将缓存年龄设置为一周。因此,它可以正常工作一周,如果我将设备时间更改为一周以上,那么它将从服务器加载,而不是从缓存中获取,我需要的是在过期后,它应该从服务器获取新响应,并且应该一直保持到缓存过期。我的拦截器如下所示

  private class CacheInterceptor implements Interceptor {

        Context mContext;

        public CacheInterceptor(Context context) {
            this.mContext = context;
        }

        @Override
        public Response intercept(Chain chain) throws IOException {
            Request request = chain.request();

                request = request.newBuilder()
                        .header(HEADER_SESSION_ID, sessionId)
                        .header(HEADER_MOBILE_OS, Constants.MOBILE_OS)
                        .build();
            }
            Response response = chain.proceed(request);
            return response.newBuilder()
                    .header("Cache-Control", "public, max-age=" + CACHE_MAX_AGE)ONE_WEEK).build();
        }
    }
}
有谁能引导我度过这一关吗