Skip to content

Commit

Permalink
Remove deleted entities from global instance cache
Browse files Browse the repository at this point in the history
  • Loading branch information
dhennessy committed Sep 19, 2013
1 parent 13a0fb8 commit 2c76698
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions FCModel/FCModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ - (void)registerUniqueInstance
dispatch_semaphore_signal(g_instancesReadLock);
}

- (void)removeUniqueInstance
{
id primaryKeyValue = self.primaryKey;
if (! primaryKeyValue || primaryKeyValue == [NSNull null]) return;
[self.class uniqueMapInit];

dispatch_semaphore_wait(g_instancesReadLock, DISPATCH_TIME_FOREVER);
NSMapTable *classCache = g_instances[self.class];
[classCache removeObjectForKey:primaryKeyValue];
dispatch_semaphore_signal(g_instancesReadLock);
}

+ (instancetype)instanceFromDatabaseWithPrimaryKey:(id)key
{
__block FCModel *model = NULL;
Expand Down Expand Up @@ -646,6 +658,7 @@ - (FCModelSaveResult)delete
existsInDatabase = NO;
[self didDelete];
[NSNotificationCenter.defaultCenter postNotificationName:FCModelDeleteNotification object:self.class userInfo:@{ FCModelInstanceKey : self }];
[self removeUniqueInstance];

return FCModelSaveSucceeded;
}
Expand Down

0 comments on commit 2c76698

Please sign in to comment.