8

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?

Ben Hoyt
  • 10,694
  • 5
  • 60
  • 84
  • That information may very well be private to Apple. They might rather it suffice that it 'just works'. – Patrick Perini Jul 27 '11 at 16:05
  • From their docs it seems like that's the case. Kinda rough, I think -- they make a big deal of the caching and cache sizes, but don't tell you how they determine what's going to stay in or be dumped from the cache. Could well affect performance in (for example) a photo-viewing app. – Ben Hoyt Jul 27 '11 at 18:01
  • It could also be dynamic. It's possible that it changes approaches depending on circumstance. – Patrick Perini Jul 27 '11 at 19:35

2 Answers2

3

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.

Josh
  • 3,445
  • 5
  • 37
  • 55
  • Thanks, that's very interesting. As you mention, it isn't Apple's version of `NSURLCache`, and potentially theirs could work totally differently, but awarding you the bounty for real effort anyway. Thanks! :-) – Ben Hoyt Aug 03 '11 at 14:59
1

I would guess that you're going to have to write some test cases to figure it out. (And, of course, be aware that the parameters may change with iOs version, hardware platform, etc.)

Hot Licks
  • 47,103
  • 17
  • 93
  • 151