Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Core Data cache transient attributes?

I have the following scenario:

  • entity with a transient attribute used for sectioning
  • web-based data model periodically refreshed
  • NSFetchedResultsController

Everything works fine, but when I do a refresh, that transient attribute seems to be getting out of date.

The attribute is returned by an accesssor in my entity object. I tried setting a breakpoint in the accessor, and notice that it's not actually called when my app starts up and my NSFetchedResultsController. This seems to indicate that Core Data is caching this value somewhere (since my table is still section properly). Is there a way to clear this cache?

like image 346
Ben Gottlieb Avatar asked Feb 27 '23 16:02

Ben Gottlieb


1 Answers

Yes. Use

+ (void)deleteCacheWithName:(NSString *)name;

The name is the one you provided during NSFetchedResultsController initialization time, when calling

- (id) initWithFetchRequest:(NSFetchRequest *)fetchRequest managedObjectContext:(NSManagedObjectContext *)context sectionNameKeyPath:(NSString *)sectionNameKeyPath cacheName:(NSString *)name;

setting the cacheName argument.

Alternatively, you can avoid Core Data caching the data during NSFetchedResultsController initialization time: simply pass nil for the cacheName argument.

like image 120
Massimo Cafaro Avatar answered Mar 11 '23 08:03

Massimo Cafaro