gpt4 book ai didi

android - picasso 不在磁盘上缓存图像

转载 作者:太空狗 更新时间:2023-10-29 14:00:41 27 4
gpt4 key购买 nike

我必须使用自定义 OkHttpClient,这样我才能将 header 添加到图像请求中。问题是 Picasso 不会因此而在磁盘上缓存任何图像。我使用 setIndicatorsEnabled(true) 检查缓存,但我只看到红色指示器。当我使用默认的 OkHttpDownloader 时,一切正常。下面是我的 Picasso 初始化代码。那么有没有人遇到同样的问题呢?

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

最佳答案

啊,因为当您更改 header 时会发生这种情况,您很可能没有设置 Cache-Control header

根据 Jake wharton( picasso 的开发者之一)

Picasso doesn't have a disk cache. It delegates to whatever HTTP client you are using for that functionality (relying on HTTP cache semantics for cache control). Because of this, the behavior you seek comes for free

摘自 Jake Wharton 的回答 here

此外,

If you never see a blue indicator, it's likely that your remote images do not include proper cache headers to enable caching to disk

关于android - picasso 不在磁盘上缓存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35806571/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com