uwsgi_cache_lock_timeout

Sets the timeout period for the cache lock during uWSGI caching operations.

Syntaxuwsgi_cache_lock_timeout time;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The uwsgi_cache_lock_timeout directive in NGINX controls the duration for which the cache lock remains active while waiting for another request to complete its caching operation. When multiple requests attempt to retrieve cached data from uWSGI, this lock prevents cache stampedes, ensuring that only one request can obtain the cache data at any one time. If another request arrives before the lock timeout expires, it will wait for the lock to be released, thereby reducing the chance of multiple backend request processing and enhancing performance.

This directive accepts a time value as its argument, which specifies how long other requests will wait for the cache lock. The timeout is defined in terms of seconds, and a higher timeout may help in scenarios with sporadically heavy loads, but it can lead to increased request latency during high contention periods for cache access. Conversely, setting this value too low may result in multiple simultaneous requests hitting the backend if the original request takes longer than the lock timeout, negating the benefits of caching altogether.

Moreover, the uwsgi_cache_lock_timeout directive should be set in the appropriate configuration context (http, server, or location) depending on where you want to manage the caching behavior. Use this directive thoughtfully according to your traffic patterns and application response times to achieve the best caching performance.

Config Example

http {
    uwsgi_cache_path /path/to/cache levels=1:2 keys_zone=my_cache:10m;

    server {
        location / {
            uwsgi_pass my_uwsgi;
            uwsgi_cache my_cache;
            uwsgi_cache_lock on;
            uwsgi_cache_lock_timeout 5s;
        }
    }
}

Setting the timeout too low may result in cache misses as other requests may not wait long enough for a lock to release.

If cache lock timeouts are set disproportionately higher than the expected response time, it can lead to unnecessary user wait times for requests under high contention.

Not specifying a value may cause unpredictable behavior based on other configuration settings. Must always define a value or set it to 'none'.

Make sure the caching mechanism is correctly configured else this directive has no effect.

← Back to all directives