uwsgi_cache_lock_age

The `uwsgi_cache_lock_age` directive sets the time to wait for a cache lock when serving requests in NGINX with uWSGI caching enabled.

Syntaxuwsgi_cache_lock_age time;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The uwsgi_cache_lock_age directive is used in NGINX configurations to define a specific timeout period for waiting on a cache lock. When multiple requests for the same resource are received simultaneously, the cache lock mechanism prevents cache stampedes by allowing only one request to fetch the resource from the backend while the others will wait for the cache to be populated. This prevents overwhelming backends with identical requests and ensures the latest content is served to clients after the resource is cached.

The value specified for the uwsgi_cache_lock_age directive is a time duration, which controls how long other requests have to wait for the lock to be released. If the cache lock is not available and the timeout period expires, the subsequent requests may either fail immediately, or they will proceed with the backend fetching depending on configuration. The directive thus balances between performance requirements and resource management for dynamic content using uWSGI.

This directive can be utilized in various contexts within NGINX, including http, server, and location blocks. It’s particularly effective in high-traffic environments where caching is crucial to reduce backend load and improve response times.

Config Example

uwsgi_cache_lock on;
uwsgi_cache_lock_age 10s;

Setting the value too low may lead to cache stampedes if multiple requests collide.

Not enabling uwsgi_cache_lock will render this directive ineffective, as no locks will be applied.

Oversized cache lock periods can delay responses for users waiting for cache hits.

← Back to all directives