open_file_cache_events

The open_file_cache_events directive controls the caching behavior for open file events in NGINX.

Syntaxopen_file_cache_events on | off;
Defaultnone
Contexthttp, server, location
Argumentsflag

Description

The open_file_cache_events directive is part of the NGINX HTTP Core module, and it allows you to specify whether or not to cache the events associated with opening files. When enabled, NGINX will track file access events such as when a file is opened or closed, which can significantly improve performance by reducing the frequency of file system access and thus lowering I/O operations. This directive takes a single flag as an argument, which can be either 'on' or 'off', indicating whether the caching of open file events is enabled or disabled respectively.

Using this directive can significantly enhance the responsiveness of your NGINX server, especially in scenarios where files are frequently opened and closed during request handling. However, enabling this directive may lead to stale data being retrieved if files are modified outside of the NGINX process without it being aware of those changes, hence it’s crucial to choose the right balance based on your application’s needs.

When using open_file_cache_events, it should be noted that it is placed within the http, server, or location context. This directive does not have a default configuration and must be explicitly set to take effect in a configuration block where file caching is desired.

Config Example

http {
    open_file_cache_events on;
    location / {
        open_file_cache max=2000 inactive=60s;
    }
}

Enabling open_file_cache_events may lead to outdated file information if files are changed and not re-cached.

This directive should be used judiciously in high-change environments to prevent stale data.

← Back to all directives