ajp_cache_valid
The `ajp_cache_valid` directive configures caching times for specific HTTP status codes in AJP proxy responses.
Description
The ajp_cache_valid directive is a powerful tool in NGINX that allows you to define the time period for which responses with specified HTTP status codes are considered fresh in the cache when serving through the AJP protocol. This directive enhances performance by reducing the number of requests sent to the backend server by serving cached responses directly to clients when cache validity permits. You can specify multiple status codes and their corresponding cache times, thus giving you fine-grained control over cache behavior based on the type of response received from the AJP backend.
This directive must be implemented within specific contexts like http, server, or location, and it requires at least one argument—one or more pairs of status codes (like 200, 404) followed by the respective time period for caching. The time specification can be in seconds (e.g., 10s) or in a more human-readable format (e.g., 1m for one minute).
Config Example
ajp_cache_valid 200 1m; ajp_cache_valid 404 10s;
Make sure to specify valid HTTP status codes; otherwise, it won’t take effect.
The directive only operates on responses that are eligible for caching as defined by other cache-related directives.
Using very long cache times for error responses (like 404) can lead to stale content being served.