iphone - 如果我不关心图像文件的持久性,我应该在哪里存储图像文件?
我知道通常我有两个位置选择:临时文件夹或缓存文件夹。
但谁能告诉我确切的区别吗?
我的应用程序将根据用户的请求下载相当多的图像。当然,没有人需要将它们永久保存在 iPhone 的磁盘上。但我仍然需要缓存它们,以防用户在相对较短的时间内返回查看它们。
临时文件夹可以是一个可以去的地方,据我了解它将被系统清除。但什么时候才能清除呢?
对于缓存文件夹,缓存文件夹也会定期清除吗?如果不清除缓存文件夹,而我将图像写入缓存文件夹,从长远来看,会占用太多空间,对用户当然不利。
那么,有人可以给我一些提示并告诉我这两个文件夹之间的确切区别吗?
谢谢
I know normally I have two choices of places: Temporary folder or Cache folder.
But can anyone tell me the exact differences?
My app will download quite many images upon users' requests. Of course, no one need them on the disk of iphone permanently. But I still need to cache them in the case users will go back to see them in relatively short time period.
Temporary folder can be one place to go, as I understand it will be cleared by the system. But when will it be cleared?
For cache folder, will cache folder be cleared regularly as well? If the cache folder will not be cleared, and I write the images to Cache folder, that will occupy too much spaces in a longer term, and it is not good for the users of course.
So, can someone give me some hints and tell me the exact diff between these two folders?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会选择 Caches 文件夹——在 NSPathUtilities.h 中查找相关方法来获取该文件夹。 Caches 文件夹不会被备份,但也不一定会被清空,temp 文件夹也不会被清空。
/tmp
通常会在重新启动时被清除(嗯,有可能),但在 iPhone 上这种情况并不常见。最好的方法是使用某种基于日期的方案将数据放入缓存文件夹中,以便您可以在认为有用时自行清除其内容。您可以使用文件的创建或修改日期来通知此决定,并且只需在每次启动(或每次进入前台事件)时进行扫描即可确定哪些项目足够旧以至于应将其删除。
I would go with the Caches folder— look in NSPathUtilities.h for the relevant methods to get at that one. The Caches folder won't be backed up, but it won't necessarily be emptied either, and neither will the temp folder.
/tmp
would normally be cleared upon reboot (well, potentially), but on the iPhone that's not something that will happen commonly.The best approach would be to put data into the Caches folder using some date-based scheme, so that you can clear its contents yourself when you deem it useful to do so. You could use the file's creation or modification date to inform this decision, and simply scan at each launch (or each enter-foreground event) to determine which items are old enough that they should be removed.