问题
I am using Picasso
to load image in my application but i facing a issue that my image URL
is same but image is changing from backend
calling the same URL but Picasso
loading the same image saved in its cache. Now i want to clear the cache for that Image and reload the image again.
What i have tried i searched on SO find that we can use picasso.invalidate(fileName);
or memoryPolicy(MemoryPolicy.NO_CACHE)
but i am getting the error message in code
Can't reslove method invalidate
Can't reslove method memoryPolicy
dependency for picasso in gradle :
compile 'com.squareup.picasso:picasso:2.4.0'
回答1:
invalidate()
and memoryPolicy()
were introduced in later versions of the library. To use either of them update picasso to the latest version
compile 'com.squareup.picasso:picasso:2.5.2'
回答2:
Try to use this.
Picasso.with(context).invalidate(url);
Picasso.with(context).load(url).networkPolicy(NetworkPolicy.NO_CACHE).memoryPolicy(MemoryPolicy.NO_CACHE);
compile 'com.squareup.picasso:picasso:2.5.2'
回答3:
append at the end of url "?=" + System.currentTimeMillis();
回答4:
use okhttp client for picasso like below
okHttpClient = new OkHttpClient();
picasso = new Picasso.Builder(this)
.downloader(new OkHttpDownloader(okHttpClient))
.build();
and if it didn't work set okhttp client cache control to network
setCacheControl(CacheControl.FORCE_NETWORK);
回答5:
Picasso supports both download and error placeholders as optional features and latest version in gradle. Check url in your code when calling each time
Picasso.with(context)
.load(url)
.placeholder(R.drawable.user_placeholder)
.error(R.drawable.user_placeholder_error)
.into(imageView);
来源:https://stackoverflow.com/questions/40459000/how-to-clear-cache-and-reload-image-in-picasso