mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

cache.db is in the wrong place

Open jaymooney opened this issue 11 years ago • 13 comments

Apple rejected our app because cache.db "violates iOS Data Storage Guidelines", it's in Library when it should be in Library/Caches so that it is not backed up in iTunes or iCloud. Should be as simple as changing NSLibraryDirectory to NSCachesDirectory- https://github.com/mapbox/mapbox-gl-native/blob/master/platform/ios/MGLMapView.mm#L27

jaymooney avatar Feb 13 '15 01:02 jaymooney

Thanks for this! Please get in touch about what you're building; we'd be curious :-) [email protected]

incanus avatar Feb 13 '15 01:02 incanus

Sorry, we need to discuss this a bit more first.

incanus avatar Feb 13 '15 01:02 incanus

We used NSLibraryDirectory on purpose here, since NSCachesDirectory content may be deleted in case the device runs out of memory. However, when using Mapbox GL as a offline mapping application, this is not desirable, since the map will be deleted, e.g. when the user is abroad and doesn't have internet access.

Instead of moving to the caches directory, we could exclude this file from being backed up with NSURLIsExcludedFromBackupKey.

kkaefer avatar Feb 13 '15 01:02 kkaefer

The way we have handled this in past with the other toolkits learned from experience and app rejections like this.

The iOS SDK puts things in Library/Application Support since the performance caching and the offline mechanism are combined. We wanted to default to keeping things around because most users want to consider offline maps as "documents" not "caches", thus they are backed up to iCloud this way. For exceptions, we recommend the dev use NSURLIsExcludedFromBackupKey.

For MBXMapKit, performance caching goes in Library/Caches and offline map documents go into Library/Application Support (the model from which we will likely borrow for GL and which has been ported to the Android SDK).

For this toolset, we should put the current caches in Library/Caches because that's what they are — caches. When we implement true offline maps (not opportunistic use of possibly-cached maps), we can put them in Library/Application Support so they are backed up.

incanus avatar Feb 13 '15 01:02 incanus

I use Android's cache dir.

ljbade avatar Feb 13 '15 02:02 ljbade

Reviewing Apple's documentation on File System Basics for insights.

ios_app_layout_2x

bleege avatar Mar 04 '15 15:03 bleege

/Library/Caches Documentation

On iOS 5.0 and later, the system may delete the Caches directory on rare occasions when the system is very low on disk space. This will never occur while an app is running. However, you should be aware that iTunes restore is not necessarily the only condition under which the Caches directory can be erased.

Based on Apple's Documentation and what @incanus said above /Library/Caches seem the way to go for now. Will confirm current status in master next.

For this toolset, we should put the current caches in Library/Caches because that's what they are — caches. When we implement true offline maps (not opportunistic use of possibly-cached maps), we can put them in Library/Application Support so they are backed up.

bleege avatar Mar 04 '15 15:03 bleege

Confirmed that the current master branch puts the cache.db in the Library directory (see below for full path) via NSLibraryDirectory. Will update to put it in /Library/Caches.

/Users/brad/Library/Developer/CoreSimulator/Devices/B251E359-3B42-4375-9429-7CCA77953B0A/data/Containers/Data/Application/CB41C924-92DD-49E8-A4CC-E3A643AFA17F/Library

bleege avatar Mar 04 '15 15:03 bleege

Converted to NSCachesDirectory and confirmed that the /Library/Caches path was configured. Will commit and merge.

/Users/brad/Library/Developer/CoreSimulator/Devices/B251E359-3B42-4375-9429-7CCA77953B0A/data/Containers/Data/Application/907CC2A0-E06A-4F5A-ABF1-66E45E92F18A/Library/Caches

bleege avatar Mar 04 '15 15:03 bleege

Just committed change. For future reference here's Apple's NSSearchPathDirectory enum documentation for finding iOS's built in directories. Also, here's Apple's guide on how to exclude a directory / file from iCloud backup... please note that this has to be applied at the iOS level and not at the Core GL level.

bleege avatar Mar 04 '15 16:03 bleege

We are good here. Summarizing chat, when we have true offline map documents, they will live in /Library/Documents and get backed up to iCloud. Performance and reliability-related caches will always live in /Library/Caches. At some point, we may also enable an API for excluding offline maps from iCloud backup using NSURLIsExcludedFromBackupKey.

incanus avatar Mar 04 '15 16:03 incanus

Heads up that Apple will reject apps that store documents in /Library/Documents that do not have the NSURLIsExcludedFromBackupKey attribute applied and take up a significant amount of space and can easily be downloaded again. I know this from experience.

postmechanical avatar Mar 17 '16 22:03 postmechanical

Thanks for the heads-up. #4372 moves the cache into ~/Library/Application Support. #4493 excludes the cache from backups.

1ec5 avatar Mar 29 '16 01:03 1ec5