[英]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.