Reputation: 28248
I use CoreData extensively in my app for viewing products. All data syncing is done in the background on a separate NSManagedObjectContexts and when syncing of changes is complete I call mergeChangesFromContextDidSaveNotification
This works perfectly 99% of the time. Here is where it is breaking down:
I believe what is happening is CoreData is serving up a cached version of the product and the fresh one is not served until after the app is restarted of I have viewed a bunch of other items.
How can I clear this cache after my mergeChangesFromContextDidSaveNotification
has been called?
This is driving me and my clients crazy - anyone know how I can remedy this situation?
Upvotes: 1
Views: 289
Reputation: 28409
Well, there could actually be a lot of reasons for this. One of the big advantages of Core Data is its flexibility... which is also one of its big drawbacks.
You have a ton of knobs that can be set on your database that relate to caching and fetching. One of the easiest, though, is if the fetch goes to the database or just to the most recent MOC.
Namely, you should look at these:
- (BOOL)includesPendingChanges
- (BOOL)shouldRefreshRefetchedObjects
Also, make sure you are handling the background update and DidSave notification properly, because the MOC should have merged those changes.
Unfortunately, Core Data has some, let's say, hard to discover, interactions when using multiple MOCs. You must be very careful to follow all the rules.
Upvotes: 2