If you need to cache hundreds of files on disk for an iOS app, is it prudent to store them all in the app's Document folder? (They will be cached then deleted after 24-48 hours.) Are there any drawbacks, eg, searching for a given file is slower if the folder has too many files? Or should you store them in separate folders for performance reasons? What is considered best practice for iOS?
You probably don't want to store them in the Documents folder as these can be accessed via iTunes file sharing. You usually store them in a cache directory. You can access cache URL's by using
[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask].firstObject
Depending on if these files shouldn't be deleted by iOS if the system is running out of storage space you might want to use the Library directory instead of caches by passing NSLibraryDirectory
into the method above instead of NSCachesDirectory
see https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html for a more detailed explanation of the different storage types on iOS
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.