How to clear cache and Reload Image in Picasso?

时光总嘲笑我的痴心妄想 提交于 2021-02-07 13:21:26

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!