Skip to content

Commit

Permalink
Add convenient method to clean all loaded (cached) instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Kjuly committed Jul 7, 2016
1 parent 9ca7e6c commit b8e1083
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions FCModel/FCModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ typedef NS_ENUM(NSInteger, FCModelSaveResult) {
// if you perform SELECTs from multiple threads.
+ (NSArray *)allLoadedInstances;

// Convenient method to clean all loaded (cached) instances
+ (void)cleanAllLoadedInstances;

// Feel free to operate on the same database object with your own queries. They'll be
// executed synchronously on FCModel's private database-operation queue.
// (IMPORTANT: READ THE NEXT METHOD DEFINITION)
Expand Down
7 changes: 7 additions & 0 deletions FCModel/FCModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ + (NSArray *)allLoadedInstances
return instances;
}

+ (void)cleanAllLoadedInstances
{
dispatch_semaphore_wait(g_instancesReadLock, DISPATCH_TIME_FOREVER);
[g_instances removeAllObjects];
dispatch_semaphore_signal(g_instancesReadLock);
}

+ (instancetype)instanceWithPrimaryKey:(id)primaryKeyValue { return [self instanceWithPrimaryKey:primaryKeyValue databaseRowValues:nil createIfNonexistent:YES]; }
+ (instancetype)instanceWithPrimaryKey:(id)primaryKeyValue createIfNonexistent:(BOOL)create { return [self instanceWithPrimaryKey:primaryKeyValue databaseRowValues:nil createIfNonexistent:create]; }

Expand Down

0 comments on commit b8e1083

Please sign in to comment.