Hugo Houyez
Hugo Houyez

Reputation: 490

Clear network cache using Picasso

I'm using Picasso to load image into my ImageView like this :

Picasso.with(getContext())
       .load(store.getString("profile"))
       .placeholder(R.drawable.ic_nothumb)
       .resize(120, 120)
       .into(iv);

Where store.getString("profile") = a string representing my url.

However even if the path don't change, when I update the image within the same path, Picasso still loading the previous image.

I've read that we can clear the network cache but I can't find a way to use .invalidate() method nor .cachePolicy() or .networkPolicy() when I try to use them I have unresolved symbol.

EDIT: I updated my Picasso version to compile

"com.squareup.picasso:picasso:2.5.2"

And now I can use .networkPolicy(), however I got this error I can't find any solution to fix it :

E/AndroidRuntime: FATAL EXCEPTION: main Process: dev.com.diaginfo, PID: 10614 java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/picasso/NetworkPolicy; Caused by: java.lang.ClassNotFoundException: Didn't find class "com.squareup.picasso.NetworkPolicy" on path: DexPathList

Upvotes: 0

Views: 406

Answers (2)

manabreak
manabreak

Reputation: 5597

You have to tell Picasso explicitly not to cache the image:

Picasso.with(getContext())
    .load(store.getString("profile"))
    .placeholder(R.drawable.ic_nothumb)
    .resize(120, 120)
    .networkPolicy(NetworkPolicy.NO_CACHE)
    .into(iv);

Upvotes: 1

Dinu
Dinu

Reputation: 600

Picaso use ur url as key for caching. when updating the image use a time stamp to over come this. I have used and it worked like a charm

Upvotes: 0

Related Questions