[英]What's the best way to limit the size of a Core Data store?
I have an app that will get Core Data objects from a server. 我有一个将从服务器获取核心数据对象的应用程序。 The number of items may be very large.
项目的数量可能非常大。 What's the best way to limit the number of items that Core Data will store so I don't use too much space on the phone?
限制Core Data存储的项目数量的最佳方法是什么,这样我就不会在手机上占用过多的空间? I was thinking that for ordered items, in
applicationWillTerminate
I could mark all but the first N items as toDelete
and then delete them the next time the app starts (per this article http://inessential.com/2014/02/22/core_data_and_deleting_objects ). 我以为对于有序项目,在
applicationWillTerminate
我可以将除前N个项目toDelete
所有项目都标记为toDelete
,然后在下次应用启动时将其删除(根据本文http://inessential.com/2014/02/22/core_data_and_deleting_objects )。 Any thoughts? 有什么想法吗?
As often happens, what strategy is good depends on how people use your data. 通常,哪种策略有效取决于人们如何使用您的数据。 What data is more important to keep available?
哪些数据对保持可用更为重要? What is less important?
什么不那么重要?
Keeping the first N
items in an ordered relationship is a simple rule, and fairly easy to implement. 将前
N
项目保持在有序关系中是一个简单的规则,并且相当容易实现。 But whether it's good for your app depends on what that data is, how a person would use it, and whether not having the rest of the related objects is likely to matter. 但是,它对您的应用程序是否有利取决于数据是什么,人们将如何使用它以及是否没有其他相关对象可能很重要。 You don't even need a
toDelete
flag, you just need to know the value of N
. 您甚至不需要
toDelete
标志,只需要知道N
的值即可。 But keep in mind that you can't rely on applicationWillTerminate
actually being called, so it's a bad place to put critical code. 但是请记住,您不能依赖
applicationWillTerminate
实际上被调用,因此放置关键代码是一个不好的地方。
Other strategies might include: 其他策略可能包括:
These are more complex, requiring date tracking in your persistent store. 这些更为复杂,需要在持久性存储中跟踪日期。 Only you can really say whether the advantages are worth that complexity.
只有您才能真正说出优势是否值得这种复杂性。
Starting out though, a more important question is: does this even matter? 不过,从一个更重要的问题开始:这是否重要? How many items is "very large"?
“非常大”有多少个项目? Does a "very large" number of items translate into a lot of data, or just a lot of little items?
“大量”项目会转换为大量数据还是只是少量项目?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.