fastcgi_cache_lock_age
The `fastcgi_cache_lock_age` directive configures the time to wait for a `FastCGI` cache lock to become available before the request is retried.
Description
The fastcgi_cache_lock_age directive within the NGINX HTTP module defines the maximum time in seconds that a request should wait for a FastCGI cache lock to become available when the cache is already locked by another request. When multiple requests are made for the same resource, and if the cache is locked due to another request processing the same content, this directive helps prevent requests from pending indefinitely. Instead, a defined waiting period (specified by this directive) allows requests to be retried after a set duration. This helps optimize the response time for users and improves overall server performance by avoiding excessive waiting.
The parameter for fastcgi_cache_lock_age is specified in seconds and accepts an integer value. For instance, if this directive is set to 10, any request that encounters a cache lock will wait for a maximum of 10 seconds before giving up on obtaining the lock and proceeding with a fresh request. Settings that are too high can lead to delays in responding to users, while settings that are too low may result in unnecessary cache misses. Administrators should balance the fastcgi_cache_lock_age parameter based on the expected cache access patterns for their applications and the acceptable latency for end-users.
Config Example
location /app {
fastcgi_pass 127.0.0.1:9000;
fastcgi_cache my_cache;
fastcgi_cache_lock on;
fastcgi_cache_lock_age 10;
}Setting a very high value can lead to prolonged delays in response times, especially under high traffic when caches are frequently locked.
If fastcgi_cache_lock is not enabled, fastcgi_cache_lock_age will have no effect.