1

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?

Paul Cezanne
  • 8,629
  • 7
  • 59
  • 90
MonkeyBonkey
  • 46,433
  • 78
  • 254
  • 460

1 Answers1

6

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.

featherless
  • 2,118
  • 19
  • 19
  • Hi, thanks for the answer. How long is the cache duration then for the disk and in-memory objects? Does it just keep it on disk and in memory until it hits some predetermined limit, maxNumberOfPixelsUnderStress, which I should manually set? Does that setting apply to disk cache as well? How would I globally disable disk cache by default for images in my application? – MonkeyBonkey Sep 03 '11 at 11:21
  • > How long is the cache duration then for the disk and in-memory objects? http://jverkoey.github.com/nimbus/interface_n_i_image_memory_cache.html The global in-memory cache defaults to being unbounded in any sense. Without modifying the maxNumberOfPixels property the only way an image will be removed from the cache is explicitly or by expiring. The duration of the disk cache is determined by the diskCacheLifetime property on the network image view. https://github.com/jverkoey/nimbus/blob/master/src/networkimage/src/NINetworkImageView.h#L25 – featherless Sep 03 '11 at 16:03
  • Please note that maxNumberOfPixelsUnderStress will only be used when a memory warning is issued. This is the number of pixels that should remain in the cache after a memory warning is issued. Contrast this with maxNumberOfPixels which is used to limit the in-memory image cache's size every time an image is added. – featherless Sep 03 '11 at 16:08
  • "How would I globally disable disk cache by default for images in my application?" To disable the disk cache you'll have to set imageDiskCache to nil for every network image view instance you create. – featherless Sep 03 '11 at 16:09
  • hi jeff .. i need to migrate three20 to nimbus and this is urgent for me .. i mailed to you too with all the details but no repsonse .. can you please help me out in this : The question that i posted is : http://stackoverflow.com/questions/22149414/three-20-framework-removal-completely-from-an-existing-project-is-nimbus-a-goo – YogiAR Mar 05 '14 at 07:47