2

I'm using Picasso in android app loading image from web url, But I see image is not updated when I updated image on web.

Picasso.with(context).load("http://testServer.com/Images/sponsor.png").into(imageView1);

Thanks in advance.

Moudiz
  • 7,211
  • 22
  • 78
  • 156
Ashok
  • 601
  • 1
  • 17
  • 32
  • 1
    because picasso has builtin cach so it seems its reading from cashing. try to add Picasso.with(getActivity()).invalidate(file); and tell me what happen – Moudiz Oct 05 '15 at 08:00

4 Answers4

9

Picasso uses a cache mechanism, so the same image is not re-downloaded twice.

If you need to bypass this cache, you can change memory or network policy to do this.

Valentin Rocher
  • 11,667
  • 45
  • 59
  • 4
    Picasso.with(this) .load(url) .memoryPolicy(MemoryPolicy.NO_CACHE) .networkPolicy(NetworkPolicy.NO_CACHE) .into(imageView); – Ashok Oct 05 '15 at 16:23
  • Disabling cache working fine, but taking more time to load. I'm using png images, if I use JPG is there any advantage !? in faster loading ? – Ashok Oct 05 '15 at 16:24
  • This takes longer because it downloads the image each time. If you just want to invalidate cache to force re-download, you could use @Moudiz's answer – Valentin Rocher Oct 05 '15 at 16:27
  • Thanks, both will re-download image, is there anyway I can make it faster? My main problem is re-downloading images in Grid view. how can I deal with it? I want to load gridview images first then while scrolling up/down it should take from cache. Is there any way? – Ashok Oct 05 '15 at 16:34
  • How often do your images change? You could do something with the cache to only re-download if the image is from a certain time ago. – Valentin Rocher Oct 05 '15 at 16:36
  • This link is to clear cache http://stackoverflow.com/questions/24952627/how-picasso-actually-cache-the-images , now I need a mechanism to get event for everyday to clear cache – Ashok Oct 05 '15 at 17:38
4

Picasso has builtin caching so the image cached automaticly. try invalidating. example:

Picasso.with(getActivity()).invalidate(file);
Moudiz
  • 7,211
  • 22
  • 78
  • 156
  • @Ashok: try with: Picasso.with(getActivity()).invalidate("file:" + imageFile.getAbsolutePath()); This worked for me. – 0xPixelfrost Dec 11 '15 at 10:24
1
public  void loadImage(ImageView imageView, String image_url,Contextcontext)
{
 try 
  {
    Picasso.with(context)
    .load(image_url)
    .memoryPolicy(MemoryPolicy.NO_CACHE)
    .networkPolicy(NetworkPolicy.NO_CACHE)
    .placeholder(R.drawable.default_image)
    .into(imageView);
  }

  catch(Exception ex)
  {
    ex.toString();
  }

}
Aarav
  • 11
  • 3
0

try to download aquery library see here https://code.google.com/p/android-query/wiki/ImageLoading

Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96