uwsgi_cache_use_stale
The `uwsgi_cache_use_stale` directive allows NGINX to serve stale cached responses when encountering specific errors or conditions.
Description
The uwsgi_cache_use_stale directive controls when NGINX should serve stale cached content in response to uWSGI requests. This directive can be particularly useful to maintain service availability by allowing the use of stale cached responses while fresh content is being generated. You can specify conditions under which stale content will be served using the following arguments: 'error', 'timeout', and 'invalid_header'. For example, if the backend uWSGI server is down or times out, users can still receive cached content instead of an error page.
To utilize this directive effectively, you add it to your location block where uWSGI caching is configured. It can take multiple arguments as needed, meaning that if you specify 'timeout error', then stale content will be served in case of both a timeout and an error. This increases the robustness of your applications by reducing the number of service disruptions experienced by users. However, administrators should exercise caution to ensure the stale content is still relevant and acceptable for users before implementing this directive extensively.
Config Example
location /api {
uwsgi_pass 127.0.0.1:9000;
uwsgi_cache my_cache;
uwsgi_cache_use_stale error timeout;
}Ensure that serving stale content is acceptable for your application's use case; it could lead to serving outdated information.
Remember to define a valid cache configuration with uwsgi_cache before using uwsgi_cache_use_stale.
Combining too many options may lead to complex behaviors; test thoroughly.