java - okhttp3.3 框架中,如何设置cache?
大家讲道理
大家讲道理 2017-04-17 18:01:41
0
2
281

在okhttp3版本和以前的不一样了么,我想设置一下缓存,但是没有显示有这个setCache()方法?

public CacheResponse(File cacheDirectory) throws Exception {
  int cacheSize = 10 * 1024 * 1024; // 10 MiB
  Cache cache = new Cache(cacheDirectory, cacheSize);

  client = new OkHttpClient();
    
  // 此处会提示没有这个setCache(),我用的eclipse
  client.setCache(cache);
}
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
左手右手慢动作

3.3 Use Builder to set up Cache

OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.cache(cache);
OkHttpClient client = builder.build();
Ty80

okhttp 3.3 The code has been modified a lot. Take a look at the internal class called InternalCache

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template