4

im using picasso library to load images. However in my application, users can have profile pictures and the link for the image is constant... Picasso has no clue that the image has changed...

I tried using : .skipMemoryCache() but it wasn't an ideal solution...

Is there a way to check if there's a new picture in the same link using picasso? Thanks!

Fringo
  • 313
  • 5
  • 25

4 Answers4

4

Apparently, there is no API in the current (2.3.2) version of Picasso to achieve this (but it is a work in progress - see this bug).

That aside, if you have control of the server side, you may want to think about your design decision to provide the changing profile picture at a constant URL.

An alternative would be: Include the current profile picture URL in the profile information you retrieve. This way, your cache can use the cached image - and as soon as the profile information provides a new URL, Picasso will fetch it. In all other cases, Picasso can leverage the cache.

Patrick
  • 4,720
  • 4
  • 41
  • 71
3

I got the answer from this link

change your URL as shown below:

String imageurl = url + "?time=" + System.currentTimeMillis();

Picasso.with(getContext()).load(imageurl).into(imageView);

this worked for me. thanks

Nabeel K
  • 5,938
  • 11
  • 38
  • 68
3
Picasso.with(context)
.load(url)
.memoryPolicy(MemoryPolicy.NO_CACHE)
.networkPolicy(NetworkPolicy.NO_CACHE)
.fit()
.placeholder(YOUR PLACE HOLDER RESOURCE)
.centerCrop()
.into(imageView);
Anand Savjani
  • 2,484
  • 3
  • 26
  • 39
1

One solution is to invalidate the cache like so

Picasso.with(context).invalidate(imagePath);

The other way to force download the image which then is cached for subsequent use as mentioned in the code.

Picasso.with(context)
        .load(imagePath)
        .networkPolicy(NetworkPolicy.NO_CACHE)
        .into(userAvatar);
Kiran Ruth R
  • 902
  • 1
  • 11
  • 28