您的位置:首页 > 职场人生

IOS工程师面试被问到的问题SQLite store takes a "long time" to save怎么解决?

2012-11-02 19:38 417 查看
官方文档的描述和回答:
Problem: You are using an SQLite store and notice that it takeslonger to save to the SQLite store than it does to save the same data to an XMLstore.
Cause: This is probably expected behavior. The SQLite store ensures that all data is written correctly to disk—see“Configuringa
SQLite Store’s Save Behavior.”
Remedy: First determine whether the time taken to save will benoticeable to the user. This is typically likely to be the case only if youconfigure your application to frequently save automatically—for example, afterevery edit that the
user makes. First, consider changing the store’s save behavior (switch off full sync). Then consider saving data only after a setperiod (for example, every 15 seconds) instead of after every edit. Ifnecessary, consider choosing a different store—for example,
the binary store.

解决卡顿的方法:
1 关闭fullfsync,然后调整频率
NSPersistentStoreCoordinator *psc = <#Get a persistent store coordinator#>;

NSMutableDictionary *pragmaOptions = [NSMutableDictionary dictionary];

[pragmaOptions setObject:@"NORMAL" forKey:@"synchronous"];

[pragmaOptions setObject:@"1" forKey:@"fullfsync"];

NSDictionary *storeOptions =

[NSDictionary dictionaryWithObject:pragmaOptions forKey:NSSQLitePragmasOption];

NSPersistentStore *store;

NSError *error = nil;

store = [psc addPersistentStoreWithType:NSSQLiteStoreType

configuration: nil

URL:url

options:storeOptions

error:&error];
2如果还不满意,自己去手工每15秒调用保存(卡顿)方法,算是负载均衡(不知是否用多线程)
3使用二进制的数据流,就不会出现此问题.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐