Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re: CoreData Application not seeing up-to-date information after store updated



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.