【问题标题】:Caching not working with Picasso缓存不适用于毕加索
【发布时间】:2014-08-19 17:35:37
【问题描述】:
当我在他们的Github page 使用毕加索的示例项目时,图像正在被缓存。意味着一旦加载它们,即使我关闭互联网连接,它们也会出现。
但是当我使用 same method 从 same URL 在不同的项目中下载图像时,图像不会被缓存。我也在使用 Android 4.2.2(磁盘缓存需要 ICS+)。那么这可能是什么问题呢?
这是他们使用过的简单代码,我正在使用
Picasso.with(context) //
.load(url) //
.placeholder(R.drawable.placeholder) //
.error(R.drawable.error) //
.fit() //
.into(view);
【问题讨论】:
标签:
android
caching
picasso
image-caching
【解决方案1】:
如果您只使用 Picasso 库,则不会发生缓存。使用 okhttp 进行缓存。
例如:
如果您使用的是 picasso-2.1.1.jar,请使用 okhttp-1.2.1-jar-with-dependencies.jar 进行缓存。
否则尝试 Glide 库,它类似于 picasso 的实现。在从缓存中加载图像时效果很好....
检查滑翔
Glide Github
Example 2
【解决方案2】:
在 build.gradle 中
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// You must install or update the Google Repository through the SDK manager to use this dependency.
// You must install or update the Support Repository through the SDK manager to use this dependency.
// You must install or update the Support Repository through the SDK manager to use this dependency.
oldCompile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.google.android.gms:play-services:4.2.42'
compile 'com.squareup.retrofit:retrofit:1.6.1'
compile 'com.squareup.okhttp:okhttp:2.2.0' //updated this
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0' //updated this
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.squareup.picasso:picasso:2.5.0' //updated this
compile files('libs/robotium-solo-5.2.1.jar')
}
它既没有为我缓存图像,但是当我将 OkHttp、OkHttp-urlconnection、Picasso 更新到最新版本时,它就可以工作了。
尝试http://gradleplease.appspot.com 获取最新版本。