Domanda

I was looking at the NINetworkImageView in the Nimbus project and was curious about that the default caching settings are. Once I call setPathToNetworkImage and loads an image, does that go in the global cache? Is it smart enough to realize it's the same image if we create another networkImageView with the same pathToNetworkImage and thus avoid a network request?

Does it store it in memory or disk by default? What are the default cache durations?

È stato utile?

Soluzione

Once I call setPathToNetworkImage and loads an image, does that go in the global cache?

Yes. By default it goes into Nimbus' global in-memory image cache. Here's what's going on in the background: once an image loads and before the image is returned to the UI thread the raw image is stored in the disk cache[1]. Once the loading thread returns, the raw image is set to the UIImageView and the raw image is also stored in the in-memory cache.

Is it smart enough to realize it's the same image if we create another networkImageView with the same pathToNetworkImage and thus avoid a network request?

Yes. As long as it has all of the same configurable properties[2] then it will immediately load the image from the in-memory cache, if it exists. You can see how an image's cache key is generated here: https://github.com/jverkoey/nimbus/blob/master/src/networkimage/src/NINetworkImageView.m#L144

[1] This is because storing to the disk is a blocking operation which we do not want to block the UI thread with.

[2] If you have two network image views loading the same url but one has a different content mode then the image will need to be processed twice because the in-memory cache keys will be different. That being said, only the image URL is used for the disk cache key so we will only end up hitting the network once, caching the image, and then for the second network image view loading the image from disk and cropping it with the other content mode.

Aside: it appears that the documentation for the two cache properties is borked, so I will have to fix this.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top