samedi 18 avril 2015

How to properly cache thumbnails locally with Picasso?

I am using Picasso to load some images. My code is very basic and looks like this:



Picasso.with(this)
.load(mImageUrl)
.placeholder(R.drawable.placeholder)
.error(android.R.drawable.error)
.tag(this)
.fit()
.centerInside()
.into(mImageView);


This works just fine and I am very happy. However, I would like to change my setup to the following:



  1. If already downloaded, load local thumbnails into the imageviews with Picasso

  2. Try to download thumbnails with Picasso (my code above) and if successful, replace local thumbnails in imageviews with new thumbnails

  3. Refresh the local thumbnail cache with the thumbnails that Picasso just downloaded


With this setup I can make sure that my app can show thumbnails regardless of network connection. It will always show at least the locally most recent thumbnails.


So my question is: What's the best way to setup such a local caching system?


Aucun commentaire:

Enregistrer un commentaire