Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force re-downloading image with Picasso

I'm creating an application which is going to download image from specific url and display it on ImageView. Server changes this image over time, but url stays the same. So I want to implement such logic:

  • When app is rotated or reopened, load image from apps cache
  • When user clicks the download button, image should be re-downloaded from the network and replace the cache

How do I implement such approach with Picasso? Or maybe some other library would fit it better?

like image 479
mbz Avatar asked Mar 19 '15 12:03

mbz


1 Answers

Picasso.with(context)
    .load(url)
    .memoryPolicy(MemoryPolicy.NO_CACHE)
    .networkPolicy(NetworkPolicy.NO_CACHE)
    .fit()
    .centerCrop()
    .into(imageView);

Each NO_CACHE skips the cache on the way down to load the resource. The cached version will be updated by the new content.

like image 74
Jake Wharton Avatar answered Oct 08 '22 14:10

Jake Wharton