kean/DFImageManager

How to enable cache for each image?

Closed this issue · 1 comments

HTKT commented

Thanks for good library. Please help to explain some my questions:

  1. I would like to enable/disable cache for each image (if needed), How can i do that?
  2. In the case, the server return the large image (above 2048px resolution). how can avoid the memory issue when running on the prior device (e.g.: iPad mini, iPhone 4s)? But when running on the higher resolution device, i also want to display correct resolution.
  3. In the case, the internet connection has problem (e.g: low connection or drop connection) , is it able to reconnect or need to do manual?

Thanks for your time to read these question.

kean commented
  1. I would like to enable/disable cache for each image (if needed), How can i do that?

There are multiple ways to control caching both from the server (HTTP caching) and from the client (NSURLRequestCachePolicy and more). I've written a guide on this topic, you might want to check it out. Stack Overflow has a lot of questions on this topic too (DFImageManager uses standard NSURLCache).

*I assumed that you asked about on-disk cache. There is also a separate in-memory cache.

  1. In the case, the server return the large image (above 2048px resolution). how can avoid the memory issue when running on the prior device (e.g.: iPad mini, iPhone 4s)? But when running on the higher resolution device, i also want to display correct resolution.

See DFImageRequest class and its targetSize and contentMode options. DFImageManager is pretty good at scaling images down. Lets say you download a 2048px image and provide a targetSize around 512px. DFImageManager will only create a single 512px bitmap, it will never render image data in a 2048px bitmap. This feature is unique to DFImageManager and Nuke, I think it should work well for you. But please test everything.

The best way to handle these situations is to always download images that are optimized for the current device. Resizing is expensive (it's actually not that simple).

  1. In the case, the internet connection has problem (e.g: low connection or drop connection), is it able to reconnect or need to do manual?

You'll have to do it yourself. You might want to check out this
https://gist.github.com/kean/86fc84827301f286868a921072f76eff
https://gist.github.com/kean/c9b7b72b089328b38d62383b9b3fde5a