dets 会在使用 ram_file 选项查找时执行磁盘读取吗?

Will dets perform disk readings on lookup with ram_file option?

DETS Erlang 文档中描述了一个选项 ram_file

open_file(name, args)

{ram_file, boolean()} - Whether the table is to be kept in RAM. Keeping the table in RAM can sound like an anomaly, but can enhance the performance of applications that open a table, insert a set of objects, and then close the table. When the table is closed, its contents are written to the disk file. Defaults to false.

这将在插入或更新后执行磁盘保存

如果我用 打开 - 然后查找 - 然后关闭?

我没有查看文档,但我假设这意味着 VM 将打开文件并可能 mmap 它,所以它一直保存在内存中,它会与磁盘上的文件同步,但我认为更改仍然可以在缓存中结束,因此不会立即写入磁盘。如果您想确保所有更改都已刷新到磁盘,请使用 dets:sync/1 调用 table 强制刷新数据,这在文档中有明确说明:

This also applies to tables that have been opened with flag ram_file set to true. In this case, the contents of the RAM file are flushed to disk.

它不会在每次查找后打开或关闭文件,但它会保持打开状态直到 dets:close/1 不会在给定的 table 上调用。另一方面,为每次查找打开和关闭 table 可能很昂贵,因此这会使整个 DETS 的使用变得毫无意义。