Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should i write sqlite database file to Documents directory or Library/Caches?

I have read the Data Storage guidelines of Apple and am really confused as to where i should keep the sqlite database files i am creating in my app. I want to read from the sqlite files even when the app is in Offfline mode. I read that such files created should be kept in the Library/caches with the "do not backup" flag set. Please suggest me the right approach for doing the same.

like image 984
Shantanu Avatar asked Aug 07 '12 06:08

Shantanu


1 Answers

The answer depends on how your database files are created:

According to the Data Storage Guidelines page:

  1. Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the /Documents directory and will be automatically backed up by iCloud.

  2. Data that can be downloaded again or regenerated should be stored in the /Library/Caches directory. Examples of files you should put in the Caches directory include database cache files and downloadable content, such as that used by magazine, newspaper, and map applications.

This seems relatively clear to me: if your app programatically creates something or generates data that you want saved, put it in the "Caches" folder. If it's something unique that the customer themselves generate (via typing into a keyboard or something they manually intervened and did), put it in "Documents".

"Do Not Backup" means that the files never get sent up to iCloud and if they get lost, they have to be re-created from scratch (or re-install).

like image 66
Michael Dautermann Avatar answered Sep 22 '22 06:09

Michael Dautermann