proxy_cache_lock_age
The `proxy_cache_lock_age` directive sets the time limit that a request must wait for a cache lock to be released before a 504 response is returned. — NGINX HTTP Core
Описание
The `proxy_cache_lock_age` directive configures the duration in which a request will wait for a cached response from another request that is currently being processed. This helps reduce the number of simultaneous requests for the same resource, allowing only one request to populate the cache while other requests either wait for the response or receive the cached response as soon as it is available. When a request hits a cache miss, and another request for the same content is already being processed, the second request will wait until the first request completes, up to the duration defined by `proxy_cache_lock_age`. If the first request completes within this time, the waiting request retrieves the cached response. If the lock is not released within the specified time, the waiting request will return a 504 Gateway Timeout error. By tune this directive appropriately, you can avoid unnecessary server load for high-frequency requests that hit the cache simultaneously while optimizing response times for users. To configure `proxy_cache_lock_age`, simply define this directive within the http, server, or location context, followed by the desired time duration. It is crucial to balance the value against the expected load and response times to avoid potential performance issues.
Пример конфига
location /api {
proxy_pass http://backend;
proxy_cache my_cache;
proxy_cache_lock on;
proxy_cache_lock_age 5s;
}Setting the age too low may result in frequent timeouts, as concurrent requests might not complete quickly enough.
Not enabling `proxy_cache_lock` will cause this directive to have no effect, as the cache locking mechanism is not activated.