Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On iOS where is the NSURLCache cache stored if diskPath:nil?

Tags:

ios

nsurlcache

I've come across code that looks like this:

NSURLCache *URLCache = 
    [[NSURLCache alloc] initWithMemoryCapacity:1024 * 1024 
                                  diskCapacity:1024 * 1024 * 5 
                                      diskPath:nil];

The problem is that I haven't been able to find what's the expected behavior when diskPath is passed nil. NSURLCache docs don't explicitly describe this situation nor I have been able to figure it out with my own testing.

Where is the cache stored? or is that code above a bug?

Thanks.

like image 733
jlmendezbonini Avatar asked Jul 02 '12 19:07

jlmendezbonini


2 Answers

I had some free time today to do some testing and found the answer. Nothing exciting but if you are curious:

By default iOS will use a database named Cache.db and, as @qegal mentioned, will be stored under the default location.

like image 108
jlmendezbonini Avatar answered Nov 16 '22 02:11

jlmendezbonini


From your linked doc:

In iOS, path is the name of a subdirectory of the application’s default cache directory in which to store the on-disk cache (the subdirectory is created if it does not exist).

My best guess would be that if path is nil (meaning you did not specify a subdirectory), the cache would just be stored in the default cache directory (and not in a subdirectory). I can't test it out right now, because I'm having some computer issues. I'm also guessing that it would be stored in the default cache directory because I'm sure you would get some sort of warning or error either at runtime or when you're writing the code. I know if I wrote something like this:

[array writeToFile: nil atomically:NO];

I would get an error as I did not specify the path to which the file should be written to.

Hope this helps!

like image 29
pasawaya Avatar answered Nov 16 '22 04:11

pasawaya