scgi_cache_use_stale
The scgi_cache_use_stale directive specifies when to use stale SCGI cache data to serve client requests during certain circumstances.
Description
The 'scgi_cache_use_stale' directive controls the behavior of NGINX when serving requests with stale cached data from the SCGI cache. It allows you to define specific scenarios under which stale cached responses will be sent to the client instead of completely fetching fresh data from the backend server. The syntax takes one or more parameters that specify these conditions, such as 'error', 'timeout', 'invalid_header', and 'updating'. By enabling this feature, you can improve the user experience by ensuring requests can still be fulfilled even if the primary data source is temporarily unavailable or slow to respond.
When set, if one of the specified conditions occurs, NGINX will serve the stale cached response rather than waiting indefinitely for a fresh response. This is particularly useful in high-traffic applications where availability is paramount, as it helps mitigate latency issues by providing clients with the last known good response instead of an immediate error. The flexibility of the directive means that you can choose to allow stale data under various situations, depending on your specific application needs and tolerances for outdated information.
Config Example
location /app {
scgi_pass backend;
scgi_cache my_cache;
scgi_cache_use_stale error timeout;
}Using this directive without properly configuring a cache can lead to unexpected results or errors.
If the backend server is returning errors frequently, relying on stale cache may result in outdated information being served to users.
Not all error scenarios can be covered; ensure to define error, timeout, etc., based on your application's behavior.