The compile cache
Novis stores compiled code on disk, so a program is not compiled again at every start.
nvs run and nvs serve both read and write the cache. It has one entry for each source file, with the code of each function in that file. The name of each entry is a hash of that code and of the build environment. A changed function gives a new name, so you never clear the cache. After an edit inside one function, only that function is compiled again.
[opcache] file_cache_dir sets the directory. The default is the cache folder in the data folder, .nvsdata next to the nvs program. [opcache] file_cache = false turns the cache off.
Good to know: the directory and its parent directory must belong to the account that runs nvs, and no other ordinary account may write to them. If a directory that you set fails this check, nvs prints one warning and compiles the program at every start.
Examples
A script that runs every minute
<?nvs// Shows a small job that a scheduler starts every minute, like a `cron` job.// The first `nvs run` compiles this file and saves the result in the compile cache.// Each later run loads that result, so the job starts without compiling again.
array<string> $queue = ['welcome mail', 'invoice 1042', 'password reset'];uint $sent = 0;foreach ($queue as string $job) { echo 'sent: ', $job, "\n"; $sent = $sent + 1;}// This prints `3 jobs done`. The output is the same whether the program was compiled or loaded.echo $sent, " jobs done\n";sent: welcome mailsent: invoice 1042sent: password reset3 jobs doneChangelog
| Version | Change |
|---|---|
0.0.6 | The compile cache has one entry for each source file, with the code of each function in it. After an edit inside one function, only that function is compiled again. |
