简体   繁体   English

如何清除Android中的毕加索缓存

[英]How to clear Picasso cache memory in android

I have an issue with image i am trying to get images from server in list but if i update image from app it goes to server successfully but when i fetch new data i got old image i have cleared Picasso cache memory still old image is display here is my code. 我有图像问题,我正在尝试从列表中的服务器获取图像,但是如果我从应用程序更新图像,它将成功进入服务器,但是当我获取新数据时,我得到了旧图像,我已经清除了Picasso缓存,仍然在这里显示旧图像是我的代码。 is there any other solution for clear the cache of Picasso 是否有其他解决方案可清除Picasso的缓存

public class WorkerListAdapter extends RecyclerView.Adapter<WorkerListAdapter.MyViewHolder> {
    private static final int REQUEST_PHONE_CALL = 1;
    private List<ItemWorkerList> itemWorkerListList;
    private Context context;


    public class MyViewHolder extends RecyclerView.ViewHolder {

        public TextView tv_worker_name, tv_worker_type;
        public CircleImageView iv_worker_image;
        public ImageView iv_worker_images;
        ImageView iv_edit_provider;
        public LinearLayout ll_doc;
        public ProgressBar pb_worker;

        public MyViewHolder(View view) {
            super(view);
            this.setIsRecyclable(true);

            tv_worker_name = (TextView) view.findViewById(R.id.tv_worker_name);
            tv_worker_type = (TextView) view.findViewById(R.id.tv_worker_type);
            iv_edit_provider = (ImageView) view.findViewById(R.id.iv_edit_provider);
            iv_worker_image = (CircleImageView) view.findViewById(R.id.iv_worker_image);

            iv_edit_provider = (ImageView) view.findViewById(R.id.iv_edit_provider);
            pb_worker = (ProgressBar) view.findViewById(R.id.pb_worker);

        }
    }


    public WorkerListAdapter(Context context, ArrayList<ItemWorkerList> itemWorkerListList) {
        this.context = context;
        this.itemWorkerListList = itemWorkerListList;

    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())

                .inflate(R.layout.item_worker_list, parent, false);
        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        final ItemWorkerList itemWorkerList = itemWorkerListList.get(position);
        holder.tv_worker_name.setText(itemWorkerList.getName());
        holder.tv_worker_type.setText(itemWorkerList.getCategory());

        Picasso.get().invalidate(itemWorkerList.getImage());
        Picasso.get().invalidate(itemWorkerList.getDocument());
        if (!TextUtils.isEmpty(itemWorkerList.getImage())) {

            Picasso.get().load(itemWorkerList.getImage()).memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).into(holder.iv_worker_image, new Callback() {
                @Override
                public void onSuccess() {
                    holder.pb_worker.setVisibility(View.GONE);
                }


                @Override
                public void onError(Exception e) {

                    holder.pb_worker.setVisibility(View.GONE);
                    Picasso.get().load(R.drawable.dummy).into(holder.iv_worker_image);
                }
            });
}

you can do this - 你可以这样做 -

Picasso.with(context).load(your_url).networkPolicy(NetworkPolicy.NO_CACHE)
        .memoryPolicy(MemoryPolicy.NO_CACHE)
        .into(your_image_view);
public class Clear {

public static void clearCache (Picasso p) {
    p.cache.clear();
}}

Use like this. 这样使用。

Clear.clearCache(Picasso.with(context));

The class Clear must be in the package : Clear类必须在包中:

Because the cache is not accessible from outside that package. 因为无法从该程序包外部访问缓存。 Like in this answer: https://stackoverflow.com/a/23544650/4585226 像这个答案一样: https : //stackoverflow.com/a/23544650/4585226

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM