Skip to content

Commit b8e1083

Browse files
committed
Add convenient method to clean all loaded (cached) instances
1 parent 9ca7e6c commit b8e1083

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

FCModel/FCModel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ typedef NS_ENUM(NSInteger, FCModelSaveResult) {
7979
// if you perform SELECTs from multiple threads.
8080
+ (NSArray *)allLoadedInstances;
8181

82+
// Convenient method to clean all loaded (cached) instances
83+
+ (void)cleanAllLoadedInstances;
84+
8285
// Feel free to operate on the same database object with your own queries. They'll be
8386
// executed synchronously on FCModel's private database-operation queue.
8487
// (IMPORTANT: READ THE NEXT METHOD DEFINITION)

FCModel/FCModel.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ + (NSArray *)allLoadedInstances
139139
return instances;
140140
}
141141

142+
+ (void)cleanAllLoadedInstances
143+
{
144+
dispatch_semaphore_wait(g_instancesReadLock, DISPATCH_TIME_FOREVER);
145+
[g_instances removeAllObjects];
146+
dispatch_semaphore_signal(g_instancesReadLock);
147+
}
148+
142149
+ (instancetype)instanceWithPrimaryKey:(id)primaryKeyValue { return [self instanceWithPrimaryKey:primaryKeyValue databaseRowValues:nil createIfNonexistent:YES]; }
143150
+ (instancetype)instanceWithPrimaryKey:(id)primaryKeyValue createIfNonexistent:(BOOL)create { return [self instanceWithPrimaryKey:primaryKeyValue databaseRowValues:nil createIfNonexistent:create]; }
144151

0 commit comments

Comments
 (0)