iOS物理内存管理(文件缓存)

iOS Physical Memory Management (File Cache)

我正在将图像文件存储在Documents目录中以进行文件缓存。

1
2
3
var paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
var path = paths.stringByAppendingPathComponent(imagePath!)
data.writeToFile(path, atomically: true)

如果存储了这么多文件,将会发生什么?有自动交换功能吗?或者我可以用代码检测到它吗?

注意:我不想使用tmp目录。


那就是我想要的。谢谢@ gnasher729。

Put data cache files in the Library/Caches/ directory. Cache data can be used for any data that needs to persist longer than temporary data, but not as long as a support file. Generally speaking, the application does not require cache data to operate properly, but it can use cache data to improve performance. Examples of cache data include (but are not limited to) database cache files and transient, downloadable content. Note that the system may delete the Caches/ directory to free up disk space, so your app must be able to re-create or download these files as needed.


没有自动滑动机制来处理此类任务。它是用户数据,用户应该对其进行控制,何时写入和何时删除。您可以在应用程序中编写此类任务。您需要决定是否要
1.根据文件创建或发布后的天数进行检查
2.要检查目录中允许的最大文件数。

您每次启动应用程序时都可以在后台运行此任务。

您可以使用以下代码删除单个文件。检查此问题

[[NSFileManager defaultManager] removeItemAtPath: pathToFile error: &error];

注意-我建议您仔细阅读iOS数据存储指南,以找出哪个目录更适合您