Skip to content

Commit eb906b8

Browse files
committed
Add convenient method to clean all loaded (cached) instances
1 parent 100a4b0 commit eb906b8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

FCModel/FCModel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ extern NSString * const FCModelChangedFieldsKey;
192192
// All instances of the called class in memory. Call on a subclass, not FCModel directly. You probably don't need this, until you do.
193193
+ (NSArray *)allLoadedInstances;
194194

195+
// Convenient method to clean all loaded (cached) instances. Call on a subclass to clean for the specific table; Call on FCModel directly to clean for all tables.
196+
+ (void)cleanAllLoadedInstances;
197+
195198
// Issues SQLite VACUUM to rebuild database and recover deleted pages. Returns NO if a transaction is in progress that prevents it.
196199
+ (BOOL)vacuumIfPossible;
197200

FCModel/FCModel.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ + (NSArray *)allLoadedInstances
113113
return outArray ?: @[];
114114
}
115115

116+
+ (void)cleanAllLoadedInstances
117+
{
118+
fcm_onMainThread(^{
119+
if (self.class == FCModel.class) [g_instances removeAllObjects];
120+
else [g_instances removeObjectForKey:self];
121+
});
122+
}
123+
116124
+ (instancetype)instanceWithPrimaryKey:(id)primaryKeyValue { return [self instanceWithPrimaryKey:primaryKeyValue databaseRowValues:nil createIfNonexistent:YES]; }
117125
+ (instancetype)instanceWithPrimaryKey:(id)primaryKeyValue createIfNonexistent:(BOOL)create { return [self instanceWithPrimaryKey:primaryKeyValue databaseRowValues:nil createIfNonexistent:create]; }
118126

0 commit comments

Comments
 (0)