003 okhttp超时与缓存

  上文的介绍都没添加,如果要添加,则按照下面的方式设置。

File sdcache = getExternalCacheDir();
int cacheSize = 10 * 1024 * 1024;
OkHttpClient.Builder builder = new OkHttpClient.Builder()
        .connectTimeout(15, TimeUnit.SECONDS)
        .writeTimeout(20, TimeUnit.SECONDS)
        .readTimeout(20, TimeUnit.SECONDS)
        .cache(new Cache(sdcache.getAbsoluteFile(), cacheSize));
OkHttpClient mOkHttpClient=builder.build();

  

posted @ 2019-08-30 17:04 曹军 阅读(...) 评论(...) 编辑 收藏