本文介绍了毕加索不在磁盘上缓存图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用自定义OkHttpClient,以便可以将标头添加到图像请求.问题在于,因此,毕加索不会在磁盘上缓存任何图像.我已经使用setIndicatorsEnabled(true)来检查缓存,并且我只看到红色指示器.当我使用默认的OkHttpDownloader时,一切正常.以下是我的毕加索初始化代码.那么有人会遇到同样的问题吗?

I have to use custom OkHttpClient so I can add headers to the image requests. The problem is Picasso won't cache any images on disk because of this. I've used setIndicatorsEnabled(true) to check caching and I see only red indicators. When I use default OkHttpDownloader all is ok. Below is my Picasso initialization code. So does anyone encounter the same problem?

 public static void init(Context context) {
        Picasso.Builder builder = new Picasso.Builder(context);
        OkHttpClient client = new OkHttpClient();
        client.interceptors().add(new AuthInterceptor());
        Downloader downloader = new OkHttpDownloader(client);
        Picasso.setSingletonInstance(builder.downloader(downloader).build());
        Picasso.with(context).setIndicatorsEnabled(true);
    }

还有我的图片下载代码

 public static void load(final ImageView imageView, final Image image) {
            Picasso.with(imageView.getContext())
                    .load(image.getUrl())
                    .resize(400, 0)
                    .memoryPolicy(MemoryPolicy.NO_CACHE)
                    .into(imageView);
    }

推荐答案

由于更改标头时会发生这种情况,因此您很可能没有设置Cache-Control标头

Ah since this is happening when you change headers, you are most probably not setting the Cache-Control header

根据杰克·沃顿(毕加索的开发者之一)

According to Jake wharton (One of the developer of Picasso)

摘自Jake Wharton的回答此处

Taken from Jake Wharton's answer here

这篇关于毕加索不在磁盘上缓存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-16 03:58