Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 315
Ben Hoyt Avatar asked Jul 22 '11 21:07

Ben Hoyt


People also ask

What is NSURLCache?

The NSURLCache class implements the caching of responses to URL load requests, by mapping NSURLRequest objects to NSCachedURLResponse objects. It provides a composite in-memory and on-disk cache, and lets you manipulate the sizes of both the in-memory and on-disk portions.

What is Nscache?

A mutable collection you use to temporarily store transient key-value pairs that are subject to eviction when resources are low.


1 Answers

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.

like image 60
Josh Avatar answered Oct 09 '22 20:10

Josh