毕加索为什么不保存图像缓存供脱机使用?
问题描述:
我有以下代码,如预定装载图像脱机其不列入。它在线运行良好,但我也需要离线加载图像。我已经授予了编写外部存储的权限。任何想法都会非常有帮助。毕加索为什么不保存图像缓存供脱机使用?
Picasso.with(getContext())
.load(userInfo.getUserPictureUri())
.networkPolicy(NetworkPolicy.OFFLINE)
.resize(80, 80)
.error(R.drawable.profile_picture)
.centerCrop()
.into(imageView_ProfilePictureSide, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
// Try again if cache failed
Picasso.with(getActivity())
.load(userInfo.getUserPictureUri())
.error(R.drawable.profile_picture)
.into(imageView_ProfilePictureSide);
}
});
答
添加OkHttp到应用程序模块的gradle这个构建文件:
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp:okhttp:2.4.0'
毕加索使用HTTP
客户端请求Disk Cache
操作,从而可以使你自己的HTTP请求头具有财产Cache-Control
与max-age
并创建自己的静态毕加索实例,而不是默认的毕加索通过使用Okhttp
。
无论是Okhttp
和picasso
库由squareup团队提供。
参考文献:How do I use disk caching in Picasso?和Github issue about disk cache,两个问题已经被@杰克 - 沃顿回答 - >Question1和Question2
数据从一个GET请求来吗? – Bawa
哪些数据?雅,图像的URL是得到请求 –
https://stackoverflow.com/questions/23978828/how-do-i-use-disk-caching-in-picasso –