re: CoreData Application not seeing up-to-date information after store updated
re: CoreData Application not seeing up-to-date information after store updated
- Subject: re: CoreData Application not seeing up-to-date information after store updated
- From: Ben Trumbull <email@hidden>
- Date: Tue, 13 Nov 2007 20:56:12 -0800
Andrew,
I use [NSManagedObjectContext refreshObject:parentObject
mergeChanges:YES] in App A when the notification that the store has
been updated is received. I've also tried using the same message with
a mergeChanges:NO to turn the objects back into a fault - to no avail.
If I quit and relaunch App A then the parent -> child (and inverse)
relationships match exactly what was set in App B.
Can anyone give me some suggestions of other ways to refresh the
relationships in the parent object in App A ? Is there something else
I need to do besides using the refreshObject message ?
If we were to model the relationship, we'd get something like:
NSManagedObjectContext <<-> Application <<->> Database
(App can have multiple contexts, apps can use multiple databases,
databases can be in use by multiple apps)
The piece that isn't apparent (although pretty such I've covered this
in the archives) is the caching that goes on beneath the
NSPersistentStoreCoordinator.
MOC <<-> PSC <<-> Application <<->> Database
-refreshObject:mergeChanges: basically clears/refresh at the level of
the MOC. If the PSC has some of the data you care about cached, then
when the data is viewed again, you'll still see the old cached data.
For your scenario, the easiest thing to do is, before refreshing,
execute a fetch request to grab the parent and set the keypaths to
prefetch the children. Fetch requests always bring the most recent
data from the database into memory (cached within the PSC). This can
be expensive, as it means a fetch request always performs I/O.
Mitigating the expense is the cache used by faulting, and that's
(probably) why you're seeing stale data.
You can also use the MOC's staleness interval to solve this problem
more broadly to prevent cached data from being reused after a certain
length of time.
--
terminally curious,
-Ben
__________________________________________________________________________
Ben Trumbull
email@hidden Development Technologies
(408) 974-5790 Core Data
Change is the Epitome of Hope. Apple, Inc.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden