Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way of sharing a Core Data store between processes?

What am I trying to do?

  1. A UI process that reads data from a Core Data store on disk. It wouldn't need to edit the data, just read and display the data.

  2. A command line process that writes to the same data store as accessed by the UI.

Why?

So that the command line process can be running all the time but the user can quit the UI process and forget about the app until they need to look at the data it's captured.

What would be the simplest and most reliable way of achieving this?

What Have I Tried?

I've read up on sharing a data store between threads and implemented this once before, but I can't find anything in the docs or on the web indicating how to share a store between processes.

Is it as simple as pointing both processes at the same data store file? I've experimented with this briefly. It appeared to work OK, but I'm worried I might run into problems with locking etc when it's really put under stress.

Finally

I'd really appreciate someone giving me pointers on what direction to go with this. Thanks.

like image 760
John Gallagher Avatar asked Nov 07 '09 02:11

John Gallagher


2 Answers

This might be one of those situations in which you'll simply have to Try It And See™.

Insofar as I can remember, SQLite (which is the data store you'll most likely want to be using) has built in mechanisms for file locking and so on; so the integrity of the file is likely to be assured. If, on the other hand, you use the CoreData/XML approach, you might run into problems.

In other words; use the SQLite backing for your file, and you should likely be fine.

like image 90
Williham Totland Avatar answered Sep 20 '22 02:09

Williham Totland


You can do exactly what you want, you probably want to use the SQLite store otherwise saving and committing every time you want to synch out data will be horrifically slow. You just need to use some sort of IPC doorbell between the apps so that you can inform one app it needs to recheck the persistent store on disk and merge in its data.

Apple documents using multiple persistent store corindators as a valid option in Multi-Threading with Core Data (in "General Guidelines", open 2). That happens to be discussing completely parallel CD stacks in the same process, but it is valid if they are in completely separate address spaces as well.

like image 25
Louis Gerbarg Avatar answered Sep 21 '22 02:09

Louis Gerbarg