4

So, I was starting my project and wants to use Picasso in my project because its popular and used by many projects out there. I included picasso using gradle and tried loading facebook profile url with this. http://graph.facebook.com/rohitiskul/picture.

It worked very well. It loaded image from network without any issues. I restarted the app.(Without actually killing the process). It showed me the same image instantly cached in Memory. But then, I killed the app (force stop) and restarted. It took almost 10+ seconds to load the image. And that image was loading from the disk when I checked in the debug logs.

My code looks like this - In MainActivity-

Picasso.with(context)
.load("http://graph.facebook.com/rohitiskul/picture")
.into(imageView);

In application class-

Picasso picasso = new Picasso.Builder(this)
.indicatorsEnabled(true).loggingEnabled(true).build()

Picasso.setSingletonInstance(picasso);

Anyone with the similar problem? Any solution would be helpful.

I tried loading same Url with UniversalImageLoader and it was fast when fetching cached image from disk.

Edit

Earlier while playing with my app, I found out that Picasso wasn't loading the disk cached image when device was offline.

Rohit
  • 2,538
  • 6
  • 28
  • 41

5 Answers5

1

I encounter the same problem, but find only slow for the first image, later images will be fast.

Probably it needs a warm-up (loading index cache) ?

cox
  • 466
  • 4
  • 8
1

Okay i got your problem. I have fixed it by doing this

Picasso.with(context)
       .load("http://graph.facebook.com/rohitiskul/picture")
       .networkPolicy(NetworkPolicy.OFFLINE)
       .into(imageView, new Callback() {
           @Override
           public void onSuccess() { }

           @Override
           public void onError() {
               // Try again online if cache failed
               Picasso.with(context)
                      .load("http://graph.facebook.com/rohitiskul/picture")
                      .into(imageView);
           }
       });

Explanation:

  1. Picasso will look for images in cache.
  2. If it failed only then image will be downloaded over network. In your case from facebook.
Andrew Prock
  • 6,900
  • 6
  • 40
  • 60
Muhammad Laraib Khan
  • 6,508
  • 2
  • 16
  • 13
  • Helped a lot for me, cause i am making kinda offline app for my girlfriend usage. Mainly i am not connecting app to network. Just only to collect data. Big tnx! – Andris Feb 06 '19 at 12:18
0

This issue I had also faced earlier, with this what I understood that Picasso refer the cached image based on image name mentioned in the URL.

In your case you don't have image name in URL like 'image1.jpg'. Due to which Picasso is finding it difficult to read from cache and it downloads the image everytime

You can give a try to image containing the image name in URL and that will work

Fahim
  • 12,198
  • 5
  • 39
  • 57
0

Picasso doesn't offer disk cache out of the box. Instead, it relies on an Http Cache.

Make sure you add OkHttp to your dependency list.

kleinsenberg
  • 1,323
  • 11
  • 15
  • Its already there in my dependencies.. And thats why picasso return cached image from disk. Problem is that operation is too slow and relies on network somehow – Rohit Mar 14 '15 at 04:28
0

Add a string identifier with the stableKey method when making the request so Picasso can identify your requests and quickly load it from the cache.

Example:

Picasso.Builder(context).loggingEnabled(true).build()
                .load(imageUrl)
                .stableKey("myImage")
                .into(imageView)
Petermonteer
  • 296
  • 4
  • 17