Forcing Picasso to ignore cache and load from Network!

Picasso is a pretty cool image downloading and caching library for Android. Not only does it manage download and cache , it even allows you to manipulate the image by allowing basic transformations like rotate, resize, center, crop etc

In one of our recent implementations we needed to purge the cache and reset the image Picasso was caching . We faced some inconsistent behavior here. Even after using Picasso.with(getActivity()).invalidate(targetUrl); and setting a new image at the same Url . The same old image would show up. Also this would happen intermittently pointing to a timing issue ( Maybe we were loading it again before the cache could get purged…)

The following code piece finally ensure we load from the network in this specific case but also save to the cache for all future loads

Picasso.with(context).load(targetUrl).memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).into(targetView, new Callback() {…..});

Hope this helps some other Image lovers out there!!

Team Cennest!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>