我还以为我的问题,结果看她的框架,发现里面做了一个本地的缓存。
Retrofit retrofit = new Retrofit.Builder() //.client(getOkHttpClient()) .baseUrl(baseUrl) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build();
public static OkHttpClient getOkHttpClient() { if (okHttpClient == null) { synchronized (OkHttpClient.class) { if (okHttpClient == null) { File cacheFile = new File(BaseApplication.getApplication().getCacheDir(), "responses"); Cache cache = new Cache(cacheFile, DEFAULT_CACHE_SIZE); okHttpClient = new OkHttpClient.Builder() .cache(cache) .addInterceptor(REQUEST_INTERCEPTOR) .addNetworkInterceptor(RESPONSE_INTERCEPTOR) .addInterceptor(LoggingInterceptor) .build(); } } } return okHttpClient; }建议以后写框架做好注释。不然本地缓存都不知道放哪里了。