if(isConnected()) { // if device online
Picasso.with(context)
.load(url)
.networkPolicy(NetworkPolicy.NO_CACHE)
.placeholder(R.drawable.ic_contact_picture)
.error(R.drawable.ic_contact_picture)
.into(imageView, new Callback() {
@Override
public void onSuccess() { }
@Override
public void onError() {
Picasso.with(context).invalidate(url);
}
});
} else { // if device offline
Picasso.with(context)
.load(url)
.networkPolicy(NetworkPolicy.OFFLINE) // force load cached image
.placeholder(R.drawable.ic_contact_picture)
.error(R.drawable.ic_contact_picture)
.into(imageView);
}
Earlier I had an image on my server. I fetched that image using picasso and it was cached.
Now I deleted that image, so I want to invalidate that image in picasso cache. Now on refreshing the imageview when device is online, the imageview was blank and onError was executed, as per expected.
BUT,
Now when the device is offline, the else part is executed and since I've given networkpolicy.offline, picasso will be forced to show cached image, which should not exist since I had invalidated it before. Still it shows the image from the cache. Why?