An option ram_file
is described in DETS Erlang docs
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 tofalse
.
this will perform save on disk after insert or update
What if i'll use open - then lookup - then close?
I haven't checked in the docs, but I assume that this mean that the VM will open the file and potentially
mmap
it, so it is constantly kept in the memory and it will be synchronised with the file on the disk, but I think that the change still can end in the cache, so it can be not immediately written to disk. If you want to be sure that all changes have been flushed to the disk then usedets:sync/1
call on the table to force data to be flushed which is explicitly stated in the docs:It will not open nor close file after each lookup, but it will keep it opened until
dets:close/1
will not be called on the given table. Opening and closing table for each lookup on the other hand can be expensive, so it would make whole usage of DETS a little bit meaningless.