[英]Can i clear cache of safari from my ios app is there any method or its sandboxed
[英]iOS app: When should I clear my cache data? (using Realm)
在我的iOS应用中,我将特定数据(包含缓存模型的Realm DB)保存在设备的缓存目录中的磁盘上。 当用户使用该应用程序时,缓存数据会增加,因此我想定期清除旧的缓存数据。
问题是我不知道如何检查要删除的模型是否被当前视图使用。 (通过尝试删除所有模型,我得到一个错误,告诉您当前视图使用的某些模型对象已失效。)
为了确保当前不使用我要删除的缓存模型,当应用终止时,我目前正在清理缓存:
- (void)applicationWillTerminate:(UIApplication *)application {
[[ModelManager sharedInstance] deleteUnusedCacheModels];
}
deleteUnusedCacheModels中的示例代码:
NSDate* limitDate = [NSDate dateWithTimeIntervalSinceNow:-(60.0 * 60.0 * 24.0 * 7.0)];
RLMResults* modelProductListArray = [ModelProductList objectsInRealm:_cacheDb
where:@"modelUpdate < %@ || modelDelete = %@", limitDate, @YES];
[_cacheDb deleteObjects:modelProductListArray];
但是,如果用户不经常终止应用程序,则不会执行此代码。 (大多数用户将应用留在后台。)
有没有更好的方法来清除缓存的模型数据?
谢谢。
我得到了以下解决方案。
模型中的实现:
在服务器请求上回收缓存模型的策略:
在以下时间删除缓存:
用这样的代码:
NSDate* limitDate = [NSDate dateWithTimeIntervalSinceNow:-(60.0 * 60.0 * 24.0 * 7.0)];
RLMResults* modelProductListArray = [ModelProductList objectsInRealm:_cacheDb
where:@"modelUpdate < %@ || modelDelete = YES", limitDate];
[_cacheDb deleteObjects:modelProductListArray];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.