問題描述
我知道 UIImage 在核心數據中的存儲已經討論了很多,例如 這里,但那是 ios5 之前的版本.現在我們有了外部存儲標志,你們認為將 UIImage 直接存儲在實體中、作為單獨的實體還是仍然在磁盤上是一個好主意?
這里是解釋外部存儲選項的來源.
iOS 5.0 核心數據發布說明
<塊引用>啟用后,Core Data 會啟發式地根據每個值決定是否它應該將數據直接保存在數據庫中或將 URI 存儲到它為您管理的單獨文件.您不能根據如果使用此選項,則為二進制數據屬性的內容.
從您的鏈接 外部二進制數據,啟發式似乎是
<塊引用>小于 1MB 的對象存儲在數據庫中.為了更大的對象,創建一個外部文件和數據庫只是存儲對它的引用.
所以以下建議仍然有效:CoreData : store是否將圖像轉入數據庫?
<塊引用>- <100kb 與相關數據存儲在同一個表中
- <1mb 存儲在通過關系附加的單獨表中,以避免不必要地加載
- <塊引用>
1mb 存儲在磁盤上并在 Core Data 中引用它
該標志設置 Core Data 遵循該建議并自動將 >1MB 的圖像存儲為單獨的磁盤文件.
I know that the storing of UIImage's in core data has been discussed a lot, such as here, but that was pre-ios5. Now that we have the external storage flag, do you guys think it would be a fine idea to store UIImage's directly in the entity, as a separate entity, or still on the disk?
Here is a source explaining the external storage option.
Core Data Release Notes for iOS 5.0
When enabled, Core Data heuristically decides on a per-value basis if it should save the data directly in the database or store a URI to a separate file which it manages for you. You cannot query based on the contents of a binary data property if you use this option.
And from your link External Binary Data, the heuristic seems to be
Objects that are smaller than 1MB are stored in the database. For objects that are larger, an external file is created and the database just stores a reference to it.
So the following advice is still valid: CoreData : store images to DB or not?
- < 100kb store in the same table as the relevant data
- < 1mb store in a separate table attached via a relationship to avoid loading unnecessarily
1mb store on disk and reference it inside of Core Data
The flag sets Core Data to follow that advice and automatically store images >1MB as a separate disk file.
這篇關于使用新的外部存儲標志將 UIImage 存儲在核心數據中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!