如何在 android 中清除 Picasso 缓存内存

How to clear Picasso cache memory in android

我的图像有问题我正在尝试从列表中的服务器获取图像但是如果我从应用程序更新图像它成功地进入服务器但是当我获取新数据时我得到旧图像我已经清除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);
                }
            });
}

你可以做到 -

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();
}}

这样使用。

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

class Clear 必须在包中:

因为无法从该包外部访问缓存。就像这个答案: