dontWatchMyProfile
dontWatchMyProfile

Reputation: 46310

What's the point of having to provide a cacheName for NSFetchedResultsController?

NSFetchedResultsController *frc = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:moc sectionNameKeyPath:nil cacheName:@"Root"];

Why do we have to think about a cacheName? How important is this decision? What would happen if there are two NSFetchedResultsController instances using the exact same cacheName? Does that matter? Is that some kind of singleton stuff?

Thinking about Core Animation, there's also this strange animationID parameter, but setting it to the exact same thing for dozens of simultaneous animations doesn't hurt the animations at all. So I guess it's probably the same thing here...or not?

Upvotes: 5

Views: 957

Answers (1)

Marcus S. Zarra
Marcus S. Zarra

Reputation: 46718

If you have a UITableView with hundreds of objects that cache is very important as it will change load times from seconds to milliseconds. The trick is that a cache is one to one with its NSPredicate. If you change the predicate the cache gets rebuilt. If you change the NSPredicate constantly then the cache is useless.

If you have a table view that is consistent with regard to its NSFetchRequest then the cache will drastically improve performance.

Update

Batch size is determined when you set it and that only applies when it has to go back out to the persistent store. If there is data in the cache then it will get hit first and batch size, in my experience, is ignored.

Upvotes: 5

Related Questions