ajp_cache_use_stale

The `ajp_cache_use_stale` directive controls whether stale cached responses should be used under specific conditions when proxying requests via AJP.

Syntaxajp_cache_use_stale error timeout;
Defaultnone
Contexthttp, server, location
Arguments1+

Description

The ajp_cache_use_stale directive, when utilized in NGINX configurations, determines under which circumstances stale (outdated) cached responses can be served to clients while waiting for a fresh response from the AJP upstream server. This directive can significantly enhance the user experience by reducing latency and increasing resilience during brief outages or slowdowns on the backend services. It accepts one or more arguments that specify the conditions under which stale content may be served. Typical conditions include scenarios like an error response from the upstream server, a timeout in the upstream request, or other specified error conditions.

For instance, if set to include the timeout parameter, whenever an upstream request exceeds the configured timeout, NGINX can opt to deliver a previously cached response instead of returning an error to the client. This behavior allows for greater flexibility in how proxies respond to varying scenarios, thus minimizing disruptions in user experience. The directive can be fine-tuned by specifying several conditions, enabling a nuanced control over caching behaviors depending on operational requirements.

The directive operates in various contexts, including http, server, and location, providing configurational versatility across different levels of application architecture. By strategically enabling stale responses, developers can optimize performance, particularly in high-traffic scenarios where service continuity is paramount.

Config Example

http {
    ajp_cache_path /var/cache/ajp levels=1:2 keys_zone=my_cache:10m;
    server {
        listen 80;
        location / {
            ajp_pass my_backend;
            ajp_cache my_cache;
            ajp_cache_use_stale error timeout;
        }
    }
}

Be cautious when using stale responses, as serving outdated data may confuse users unless the cache is strictly managed.

Ensure that the cache invalidation strategies are in place to prevent serving stale data longer than necessary, especially after critical updates.

← Back to all directives