[opcache]
opcache
Controls how a running server notices that a source file changed.
Novis compiles your code and keeps the result. The server checks the files behind that result in the background, so a changed file reaches the next request without a restart. validate is how it checks: mtime compares the time each file was last changed, and hash reads each whole file. mtime is the default. revalidate_freq is how often it checks. settle is how long the files must stay unchanged before the server compiles them again.
The default of settle depends on the run mode: 1s in production and 100ms in development. A value written in the file is used in both modes.
incremental keeps two things in memory after a compile: the result of checking each file for errors, and the compiled code of each function. A reload after an edit then checks only the files that changed. It compiles only the functions that changed. The default is true in development and false in production. With false, the server frees this memory after each compile.
Good to know: a program cannot change any of these settings. Only the person who runs the server may change them.
Only nvs.toml sets this key. A request may not change it.
A change in the file takes effect a few seconds after you save it. The server does not restart.
When this host notices that the code changed
<?nvs// Shows the settings that control how a running server notices a changed source file.
// `validate` is how the server checks a file. `mtime` compares the time the file// was last changed, and `hash` reads the whole file. The default is `mtime`.echo 'validate: ', Core\Config::get('opcache.validate') ?? '(no value)', "\n";
// `revalidate_freq` is how often the server checks. Its default is `2s`. `settle` is how long// the files must stay unchanged before the server compiles them again. Here its default is `1s`.echo 'revalidate_freq: ', Core\Config::get('opcache.revalidate_freq') ?? '(no value)', "\n";echo 'settle: ', Core\Config::get('opcache.settle') ?? '(no value)', "\n";
// Only the person who runs the server may change these settings.
// `Core\Config::set('opcache.validate', ...)` does not compile,// because a program may not change `opcache.validate`.
// This program keeps the names in variables. The compiler does not check a variable, so each `set` call runs and returns `false`.string $validate = 'opcache.validate';string $revalidateFreq = 'opcache.revalidate_freq';string $settle = 'opcache.settle';echo 'check by hash: ', Core\Config::set($validate, 'hash') ? 'allowed' : 'not allowed', "\n";echo 'check on every request: ', Core\Config::set($revalidateFreq, '0') ? 'allowed' : 'not allowed', "\n";echo 'compile at once: ', Core\Config::set($settle, '0s') ? 'allowed' : 'not allowed', "\n";
// The default of `settle` depends on the run mode. It is `1s` in production// and `100ms` in development. A program cannot change the mode either.echo 'change the mode: ', Core\Config::set('mode.default', 'development') ? 'allowed' : 'not allowed', "\n";echo 'settle is still: ', Core\Config::get('opcache.settle') ?? '(no value)', "\n";validate: mtimerevalidate_freq: 2ssettle: 1scheck by hash: not allowedcheck on every request: not allowedcompile at once: not allowedchange the mode: not allowedsettle is still: 1sChangelog
| Version | Change |
|---|---|
0.0.6 | [opcache] incremental keeps two things in memory after a compile: the result of checking each file for errors, and the code of each function. A reload after an edit then checks only the files that changed. The default is true in development and false in production. |
0.0.6 | The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change. |
opcache.file_cache_dir
The directory where Novis stores compiled code.
Compiling a program takes time, so Novis writes the compiled code to disk and loads it again at the next start. [opcache] file_cache_dir is that directory. It is separate from [cache], which is the data cache that your application uses.
A program cannot change this key, and it cannot turn the cache off. The server runs the compiled code that it finds in this directory. A program that could change the directory could choose which code runs.
Good to know: a running server applies a new directory when you save the file, and the next compile writes there. Programs that are already compiled keep running. If other accounts can write to the new directory, the server keeps the old directory. The server then writes to its log that the key was not applied.
The example prints the cache settings and tries to change the directory. Core\Config::set returns false.
Only nvs.toml sets this key. A request may not change it.
A change in the file takes effect a few seconds after you save it. The server does not restart.
Where the code this host runs is read from
<?nvs// `[opcache] file_cache_dir` is the directory where the server keeps code it has// already compiled. No other setting names this directory.
// This file does not set it, so the server uses the `cache` folder in its data folder.// The full path differs on each machine, so this prints only the last folder, `cache`.echo 'artifact cache: ', Core\Path::fileName(Core\Config::get('opcache.file_cache_dir') ?? ''), "\n";
// By default the cache is on, and its size limit is `256M`.echo 'cache in use: ', Core\Config::get('opcache.file_cache') ?? '(no value)', "\n";echo 'size limit: ', Core\Config::get('opcache.file_cache_max_size') ?? '(no value)', "\n";
// `Core\Config::set('opcache.file_cache_dir', ...)` does not compile,// because a program may not change `opcache.file_cache_dir`.
// This program keeps the names in variables. The compiler does not check a variable, so each `set` call runs and returns `false`.string $cacheDir = 'opcache.file_cache_dir';string $cache = 'opcache.file_cache';
// A program cannot move this directory, so the call returns `false`. The server// runs the compiled code it reads from there.echo 'read my code from /tmp: ', Core\Config::set($cacheDir, '/tmp/mine') ? 'accepted' : 'not allowed', "\n";
// A program cannot turn the cache off either. This call also returns `false`.echo 'turn the cache off: ', Core\Config::set($cache, 'false') ? 'accepted' : 'not allowed', "\n";
// `[cache]` is a different block. It is the data cache your code reads and// writes, and it has no `dir` key.echo 'the data cache is not it: ', Core\Config::get('cache.dir') ?? '(no such setting)', "\n";artifact cache: cachecache in use: truesize limit: 256Mread my code from /tmp: not allowedturn the cache off: not allowedthe data cache is not it: (no such setting)Changelog
| Version | Change |
|---|---|
0.0.6 | The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change. |
