open_file_cache
The `open_file_cache` directive enables caching of file descriptors to improve the performance of file serving.
Description
The open_file_cache directive in NGINX is used to control the caching of file descriptors, allowing NGINX to reuse file handles for files that are frequently accessed. This reduces the overhead of opening and closing file descriptors, thus enhancing the performance of file serving in high-traffic scenarios. The directive can take one or two arguments; the first argument specifies the maximum number of file descriptors to cache, while the optional second argument defines the time period (in seconds) for which the cache remains valid before it checks for file changes. This functionality can be crucial for optimizing static file delivery, as it minimizes the impact of file system I/O operations.
Config Example
http {
open_file_cache max=1000 inactive=30;
}Setting max too high may consume excessive server memory if many file descriptors are cached, leading to potential performance degradation.
If inactive is set incorrectly, it may lead to stale file handles being used, serving outdated content.