Open swjtuhyq opened 4 years ago
添加下面的代码试试
api.test().compose(CacheTransformer.emptyTransformer())...
这个放在什么地方呢?我把你的工程弄到本地,用来访问我的接口也不会缓存 访问地址:https://dd.robelf.com/v1/states 日志: 2019-10-24 16:11:40.190 7831-7908/ren.yale.android.retrofitcachetest D/retrofitcache: ======== request: Request{method=GET, url=https://dd.robelf.com/v1/states, tags={class retrofit2.Invocation=ren.yale.android.retrofitcachetest.rx2.ApiRx2.getStates() []}} ======== request headers: ======= response header:server: nginx/1.13.2 content-type: application/json x-powered-by: PHP/7.2.21 date: Thu, 24 Oct 2019 08:10:01 GMT Cache-Control: public,max-age=0
这个跟服务器有关系吗?
RetrofitCache.getInstance().addIgnoreParam("access_token");
没有添加任何字段,我直接修改的demo里的Rx2 test
@Cache(time = 10,timeUnit = TimeUnit.MINUTES)
@GET("https://dd.robelf.com/v1/states")
Observable<ResultVO
你看看LOGCAT TAG = retrofitcache 提示是否是从缓存加载的数据
Mobile:
Android OS: 8.0
NetWork: WIFI
URL:
LIB Version:
OkHttpClient httpClient = new OkHttpClient.Builder() .cache(cache) // .cookieJar(new CookieManger(mContext.getApplicationContext())) .connectTimeout(15, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS) .protocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1)) .addInterceptor(MyInterceptor) .addInterceptor(new CacheForceInterceptorNoNet()) .addNetworkInterceptor(new CacheInterceptorOnNet()) .build();
mRetrofit = new Retrofit.Builder() .baseUrl(mApiServer) .client(httpClient) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); RetrofitCache.getInstance().init(mContext.getApplicationContext()).setDefaultTimeUnit(TimeUnit.SECONDS).setDefaultTime(30); RetrofitCache.getInstance().addRetrofit(mRetrofit); mApiService = mRetrofit.create(IApiService.class);
@Cache(time = 10,timeUnit = TimeUnit.MINUTES) @GET("v1/robot") Observable<ResultVO> getRobotInfo();
这是我的设置,不管我怎么设置时间,都不走缓存是什么原因,哪儿写错了吗?