open_file_cache_valid
The open_file_cache_valid directive specifies how long cached file information is considered valid.
Description
The open_file_cache_valid directive is used to configure the validity of cached file attributes within NGINX. It takes a single argument that specifies the duration for which the cached file information is considered valid before NGINX attempts to check the filesystem for updates. This functionality is particularly useful for optimizing the performance of file access by reducing unnecessary file system checks, thus improving response times for static file serving.
You can set this directive in the http, server, or location contexts, which provides flexibility depending on your server configuration. The argument is a time value (e.g., 30s, 5m, 1h) indicating the time duration for which the file status (such as modification times) should be considered valid. NGINX will bypass filesystem checks for files that are still within this validity period, relying on the cached information instead to serve requests.
Once the specified time period elapses, NGINX will revalidate the cached information, ensuring that changes to the files on the filesystem are recognized. It's important to carefully choose the validity duration to balance between performance (by reducing filesystem checks) and accuracy (up-to-date information from disk).
Config Example
open_file_cache active; open_file_cache_valid 30s;
Setting the value too high may cause NGINX to serve outdated file information.
Ensure that file cache is enabled with 'open_file_cache' for 'open_file_cache_valid' to take effect.