Caching doesn't work with Picasso

When I use the Picasso sample project provided on the Github page , the images get cached. This means when they are loaded, they appear even when I turn off the internet connection.

But when I use the same method to load an image from the same URL in another project, the images won't be cached. I am also using Android 4.2.2 (disk cache requires ICS +). So what could be the problem here?

Here is the simple code they used and I am using

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

      

+3


source to share


2 answers


If you are only using the Picasso library, caching will not happen. Use okhttp for caching. For example: If you are using picasso-2.1.1.jar then use okhttp-1.2.1-jar-with-dependencies.jar for caching.



Otherwise try the Glide library which is similar to picasso's implementation. Which works great when loading image from cache .... Check out info on Glide Glide Github Example 2

+3


source


In 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')
}

      



These are not cached images for me, but when I updated OkHttp, OkHttp-urlconnection, Picasso to the latest versions it worked. Try http://gradleplease.appspot.com for the latest versions.

+1


source







All Articles