R – Does Core Data cache transient attributes

core-dataiphone

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?

Best Answer

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.

Related Topic