vendredi 17 avril 2015

Picasso - keeping images on disk

I'm using Picasso to download images in my app. My understanding is that it uses a http client (HttpResponseCache or OkHttpClient) to cache these images on disk.


Without knowing much about either of these libraries, is it possible to mark certain images as permanent? In other words, I would like to download an image and guarantee that it will be available offline.


Thinking about it, I couldn't really have the disk cache go over a certain size, so I guess what I really need is to remove the TTL on the image url and allow the cache to remove images in a first in first out scenario.


In that case, can I control which image will be deleted first (by using a timestamp based on accessed, rather than downloaded)?


Update


Based on the answer from this SO question:


Android + Picasso: changing URL cache expiration


So this answers the first part of the question - we can control the TTL through the server.


After talking to a colleague, he pointed out that the http client should take into account how frequently an image is accessed (in addition to the TTL). So hopefully I don't have to worry about this either.


That leaves me with one question. I know which images I don't need anymore, can I remove an image from the disk cache?


Aucun commentaire:

Enregistrer un commentaire