I am trying to configure NSURLCache with the maximum disc capacity possible. I'm on iOS 7.
according to the docs, NSURLCache's discCapacity attribute is a NSUInteger, aka unsigned int, which should accept a maximum value of 4,294,967,295 (0xFFFFFFFF). However, using any value above 0x7FFFFFFF (2147483647) results in the value actually reporting itself as 0 and the disc cache isn't working at all.
Furthermore, using 0x7FFFFFFF (2GB), actually results in malloc errors as soon as the disc cache fills up anywhere close to the 2GB.
The only way i found this working is with a maximum value of 1GB (1073741824). When using this value, all works as expected.
I would like to use NSURLCache with as much disc capacity as possible for my application. How can i use 8 or even 16GB?
Update [adding code example as requested in comments]:
NSURLCache* sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:sizeInBytes
diskCapacity:sizeInBytes
diskPath:@"somepath"];
[NSURLCache setSharedURLCache:sharedCache];
or you can also do:
[[NSURLCache sharedURLCache] setDiskCapacity:sizeInBytes];
[[NSURLCache sharedURLCache] setMemoryCapacity:sizeInBytes];
I'd comment, but since I'm not allowed I'll add it as an answer.
This does seem to be the case that NSURLCache only allows 2GB - anything above this value will be silently ignored/fail and the cache will not function (will not return any cached responses, nor will anything be written to the disk).
Even trying to use an existing cache by specifying the path with any value above 2GB for capacity will result in the same 'non-working' cache.
I'd suggest filing a bug with Apple to either properly implement the functionality (yes some of us have a valid reason to create large caches), or to properly document its shortcomings.
This behaviour is still present in High Sierra (macOS 1.13), and I assume the same applies to current version of iOS (11).
According to the iTunes Connect Developer Guide there's a hard 2 GB limit on the size of an app. This includes the app bundle, the documents folder, and the tmp folder, the library folder (where caches are stored on disk), etc.
User contributions licensed under CC BY-SA 3.0