uwsgi_cache_background_update

The `uwsgi_cache_background_update` directive controls whether to update the cache in the background when a request misses the cache in NGINX's uWSGI caching mechanism.

Syntaxuwsgi_cache_background_update on | off;
Defaultoff
Contexthttp, server, location
Arguments1

Description

The uwsgi_cache_background_update directive is used in the context of http, server, and location blocks in NGINX configuration. When this directive is set to on, NGINX will initiate a background update of the cache when a response is not found in the cache for a specific request. This is particularly useful for reducing latency for subsequent requests, as the first request may experience a cache miss but allows the cached content to be updated transparently while the client interacts with the server.

This feature optimizes performance by minimizing the wait time for users when new content is generated. If uwsgi_cache_background_update is set to off, NGINX will not try to refresh the cache for missed requests, meaning that subsequent requests will continue to receive stale or no cached responses until a new response is manually sent to the cache. As a result, applications requiring real-time data might benefit more from a background update mechanism to ensure up-to-date responses without additional delays.

The directive takes a single parameter that can either be on or off. While using this directive, it is important to ensure that the cache storage and uWSGI application are efficiently configured to handle the background operations to avoid overwhelming the server or causing performance degradation due to concurrent background fetches. Additionally, caching strategies should be well-defined in conjunction with other caching settings in the NGINX configuration.

Config Example

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

location / {
    uwsgi_pass 127.0.0.1:9000;
    uwsgi_cache my_cache;
    uwsgi_cache_background_update on;
}

Be cautious using this directive in high-traffic scenarios where many cache misses can trigger numerous concurrent cache updates, potentially impacting application performance.

Ensure that your uWSGI application can handle concurrent requests properly when cache updates are performed in the background.

← Back to all directives