Search code examples
objective-cioscachingnsurlconnectionnsurlcache

What caching algorithm does NSURLCache use?


Apple's NSURLCache class has decent documentation, but it doesn't say what caching algorithm it uses. Is it LRU, LFU, or something else entirely?

I'm developing for the iPad, and am hoping to make use of NSURLCache's disk-caching abilities to cache photos, by using [NSURLCache setDiskCapacity] (the default seems to be 0). What's the upper limit on this value?


Solution

  • The upper limit on the disk capacity seems to be the disk capacity of the device. I can't see anything about a 'software imposed' limit.

    As for the caching algorithm, there doesn't seem to be any apple provided documentation but I did find this. It's not strictly what you asked for, but it certainly gives you an insight into what's going on. I believe this one to be using a Multi Queue Caching Algorithm (?) where it's sorted by size and then by least recently used.

    If you were making something dependant on knowing the caching algorithm, you could do some thing with this.