Skip to content

FMDatabaseQueue lacks API to enable/disable caching. (easy fix inside) #112

regexident opened this Issue Jan 14, 2013 · 2 comments

2 participants


FMDatabaseQueue should either provide access to its database's caching setting by implementing:

@property (readwrite, assign, nonatomic) BOOL shouldCacheStatements;

- (BOOL)shouldCacheStatements {
    return _db.shouldCacheStatements;

- (void)setShouldCacheStatements:(BOOL)shouldCacheStatements {
    _db.shouldCacheStatements = shouldCacheStatements;

or provide additional (convenience) init methods for directly providing the FMDatabase object:

+ (id)databaseQueueWithDatabase:(FMDatabase *)aDatabase;
- (id)initWithWithDatabase:(FMDatabase *)aDatabase;
// the database path can be obtained from the db object

so that this becomes possible:

FMDatabase *db = [FMDatabase databaseWithPath:@"..."];
db.shouldCacheStatements = YES;
FMDatabaseQueue *queue = [FMDatabaseQueue databaseQueueWithDatabase:db];

The latter solution would require the queue to copy the db in order to properly encapsulate it, hence I'd personally prefer the simple forwarding property solution as it also keeps the API cleaner.

I experienced a quite significant performance loss after wrapping my FMDatabase inside a FMDatabaseQueue, so caching would be a definite must-have here.

ccgus commented Jan 14, 2013

I thought about this a while back when I needed to do the same thing, then I realized it was super easy to just do this:

[_q inDatabase:^(FMDatabase *db) {
[db setLogsErrors:YES];
[db setCrashOnErrors:YES];
[db setShouldCacheStatements:YES];

Which is a much better solution rather than mirroring methods.

@ccgus ccgus closed this Jan 14, 2013

Ah, nice. And so obvious even. How could I have missed that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.