Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 624
dontWatchMyProfile Avatar asked Jun 14 '10 08:06

dontWatchMyProfile


1 Answers

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.

like image 115
Marcus S. Zarra Avatar answered Sep 25 '22 16:09

Marcus S. Zarra