ajp_cache_key
The `ajp_cache_key` directive defines the caching key for responses from an AJP backend in NGINX.
Description
The ajp_cache_key directive allows NGINX users to specify what components make up the cache key for AJP protocol responses. This directive lets you influence which parts of the request will be considered when caching responses, which is critical for scenarios where different requests could yield the same response. This flexibility is especially important for applications that rely on user-specific data, such as cookies. By default, a cache key does not include the hostname, which could lead to cache collisions in environments that utilize subdomains.
To configure an appropriate cache key, the directive accepts a variable-based string, allowing the inclusion of request headers, request URIs, and even cookies. For instance, a configuration such as ajp_cache_key "$host$request_uri$cookie_user"; includes the hostname, request URI, and a user-specific cookie. This ensures that distinct user responses are cached properly without being conflated with others that might share part of the URL structure but differ in context.
Config Example
location / {
ajp_pass tomcats;
ajp_cache_key "$scheme$host$request_uri";
}Omitting the $host in subdomain configurations can lead to cache conflicts.
Using overly broad cache keys may lead to excessive memory usage due to increased cache entries.