scgi_cache_background_update

The `scgi_cache_background_update` directive enables background cache updating for SCGI responses.

Syntaxscgi_cache_background_update on | off;
Defaultoff
Contexthttp, server, location
Argumentsflag

Description

The scgi_cache_background_update directive controls whether NGINX should initiate a request to the upstream server when a stale cache entry is requested. If set to 'on', when a cache entry is stale, NGINX will still serve the stale entry to the client while simultaneously fetching a fresh copy from the upstream server in the background. This improves response times while ensuring that the next request will have fresh data. Conversely, if set to 'off', NGINX will only serve the stale entry until it becomes valid again, without updating in the background. This is particularly useful for reducing latency when a request is made for a frequently accessed resource that may not have changed frequently.

To use this directive, it can be set within the http, server, or location context. Depending on the application's needs, enabling background cache updates can significantly improve perceived performance and user experience by minimizing wait times for fresh data. However, it is essential to consider the upstream server’s load when enabling this feature, as multiple background requests may lead to higher utilization of the upstream service, especially under heavy traffic conditions.

Config Example

location /app {
    scgi_pass 127.0.0.1:9000;
    scgi_cache scgi_cache;
    scgi_cache_background_update on;
}

Enabling background updates can lead to increased load on the upstream server, especially if multiple clients request stale entries simultaneously.

Make sure that cache keys are correctly configured to avoid serving old data unintentionally.

← Back to all directives