3

When i am using the sample project of Picasso given at their Github page,the images are getting cached. Means once they are loaded,they appear even when i turn off my internet connection.

But when i use the same method to download the image from the same URL in a different project, the images doesnt get cached. I am also using Android 4.2.2(ICS+ is required for disc cache). So what could be the problem here?

Here is the simple code that they have used and i am using

Picasso.with(context) //
        .load(url) //
        .placeholder(R.drawable.placeholder) //
        .error(R.drawable.error) //
        .fit() //
        .into(view);
Diffy
  • 2,339
  • 3
  • 25
  • 47

2 Answers2

3

If you're using only Picasso library then caching won't happen. Use okhttp for caching. For example: If you're using picasso-2.1.1.jar then use okhttp-1.2.1-jar-with-dependencies.jar for caching.

Otherwise try Glide library, which is similar to picasso implementation. Which works perfectly in loading the image from cache.... Check about Glide Glide Github Example 2

Harsha Vardhan
  • 3,324
  • 2
  • 17
  • 22
1

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

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

Roman
  • 2,079
  • 4
  • 35
  • 53