Android Picasso cache with server image

2019-09-11 12:27发布

问题:

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

My questions are

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

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?

回答1:

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


Edit

Direct answer:

Yes, it will make a request.

But...

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).

Here is an answer about how to make a custom downloader

And some documentation about OkHttp interceptors