Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenient method to clean all loaded (cached) instances #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions FCModel/FCModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ extern NSString * const FCModelChangedFieldsKey;
// All instances of the called class in memory. Call on a subclass, not FCModel directly. You probably don't need this, until you do.
+ (NSArray *)allLoadedInstances;

// 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.
+ (void)cleanAllLoadedInstances;

// Issues SQLite VACUUM to rebuild database and recover deleted pages. Returns NO if a transaction is in progress that prevents it.
+ (BOOL)vacuumIfPossible;

Expand Down
8 changes: 8 additions & 0 deletions FCModel/FCModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ + (NSArray *)allLoadedInstances
return outArray ?: @[];
}

+ (void)cleanAllLoadedInstances
{
fcm_onMainThread(^{
if (self.class == FCModel.class) [g_instances removeAllObjects];
else [g_instances removeObjectForKey:self];
});
}

+ (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