fastcgi_cache_lock_timeout

Sets the maximum time to wait for acquiring a lock on a FastCGI cache.

Syntaxfastcgi_cache_lock_timeout time;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The fastcgi_cache_lock_timeout directive configures the duration in which a request will wait to acquire a lock on the FastCGI cache when another request is already processing that cache entry. This is particularly useful in scenarios where requests may collide while trying to store the same cached content. If the timeout elapses before the lock is acquired, the lock request fails, thus avoiding potentially long wait times for concurrent requests and allowing them to proceed without stalling indefinitely.

This directive can help improve the response time of your application, especially under heavy load. By setting a fastcgi_cache_lock_timeout, you can finely control the time allowed for one request to wait for another, reducing latency and improving overall user experience during peak traffic times. It must be set within the appropriate context, such as http, server, or location, and takes a single argument that specifies the timeout duration.

When the configured timeout is reached, any subsequent requests may receive an alternative response or be handled differently based on the internal handling logic of the application. Therefore, careful consideration should be taken when deciding on the value for this directive to balance between locking behavior and overall performance.

Config Example

location /api {
    fastcgi_pass backend;
    fastcgi_cache my_cache;
    fastcgi_cache_lock on;
    fastcgi_cache_lock_timeout 10s;
}

Setting the timeout too low may lead to frequent failures in acquiring locks, which could cause multiple requests to be processed simultaneously and potentially lead to cache stampede issues.

Users must ensure that the fastcgi_cache_lock directive is enabled to utilize fastcgi_cache_lock_timeout effectively.

Overly long timeout values may also lead to poor performance as requests could block for extended periods.

← Back to all directives