使用OkHttp客戶端作爲HTTP傳輸的畢加索和指定的磁盤和內存緩存大小:
OkHttpClient okHttp = new OkHttpClient();
Cache cache = new Cache(ctx.getCacheDir(), cacheSize);
okHttp.setCache(cache);
// Use OkHttp as downloader
Downloader downloader = new OkHttpDownloader(okHttp);
mPicasso = new Picasso.Builder(getApplicationContext())
.downloader(downloader)).memoryCache(new LruCache(size)).build();
建立請求攔截器(例如)爲OkHttp客戶端:
// Add Cache-Control to origin response (force cache)
client.networkInterceptors().add(new Interceptor() {
private com.squareup.okhttp.Request request;
private Response response;
private String requestUrl;
@Override
public Response intercept(Chain c) throws IOException {
request = c.request();
response = c.proceed(request);
if (!request.cacheControl().noStore()
&& !response.cacheControl().noStore()) {
requestUrl = request.urlString();
// Do not cache keys or playlists
response = response
.newBuilder()
.header("Cache-Control","public, max-age=42000").build();
}
return response;
}
});
保存到stoarage? – Elltz
@Elltz,你是什麼意思?對不起,我是新來Parse – user3030130
我的意思是你有'parseFile'' f'因此將它保存到你的內部存儲器,當你需要它時你檢索它不需要再次去網絡 – Elltz