Android Picasso缓存与服务器映像 [英] Android Picasso cache with server image

查看:150
本文介绍了Android Picasso缓存与服务器映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于获取图片的网址链接,该图片可能会每天更改,但链接不会更改。

I have a URL link to get images, and that image may change everyday however the link doesn't change.

我的问题是

在这种情况下,Picasso如何知道图像已经改变并获取新图像?

In this case, how Picasso know the image has changed and grab a new image?

Picasso是否会触发对我的服务器的URL调用每次使用图像然后确定图像是否不同?

Does Picasso fires a url call to my server every-time the image is being used and then determine if the image is different or not?

推荐答案

Picasso使用HTTP标头进行缓存,所以它基本上遵循 HTTP缓存规范
如果您的服务器提供准确的标头,它将全部自动管理。
如需更好的解释,您可以查看这个关于缓存的谷歌指南

Picasso uses HTTP headers for caching, so it basically follows the HTTP Caching specification. If your server provides accurate headers, it will all be managed automatically. For a nicer explanation you can check this google guide on caching

是的,它会提出请求。

您可以使用 OkHttp <使用自定义下载程序配置Picasso如果您已将图像存储在缓存中,则手动决定不发出请求。这在处理连接问题时特别有用(即:没有互联网连接)。

You can configure Picasso with a custom downloader using OkHttp and manually decide not to make a request if you have the image already on cache. This is particularly useful when dealing with connection issues (i.e: no internet connection).

这是关于如何制作一个自定义下载器

有关 OkHttp拦截器

这篇关于Android Picasso缓存与服务器映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆