缓存不适用于毕加索

时间:2014-08-19 17:35:37

标签: android caching picasso image-caching

当我在Github page使用Picasso的示例项目时,图像将被缓存。意味着一旦它们被加载,它们即使在我关闭我的互联网连接时也会出现。

但是,当我使用相同方法从不同项目中的相同网址下载图片时,图片不会被缓存。我也在使用Android 4.2.2(光盘缓存需要ICS +)。那么这可能是什么问题呢?

以下是他们使用的简单代码,我正在使用

Picasso.with(context) //
        .load(url) //
        .placeholder(R.drawable.placeholder) //
        .error(R.drawable.error) //
        .fit() //
        .into(view);

2 个答案:

答案 0 :(得分:3)

如果您只使用Picasso库,则缓存不会发生。使用okhttp进行缓存。 例如: 如果你正在使用picasso-2.1.1.jar,那么使用okhttp-1.2.1-jar-with-dependencies.jar进行缓存。

否则尝试Glide库,这与picasso实现类似。哪个在从缓存中加载图像时效果很好.... 检查Glide Glide Github Example 2

答案 1 :(得分:1)

在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以获取最新版本。