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.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With