ajp_cache_min_uses

Sets the minimum number of requests after which a response will be cached.

Syntaxajp_cache_min_uses n;
Default1
Contexthttp, server, location
Arguments1

Description

The ajp_cache_min_uses directive is part of the NGINX AJP module that determines how many times a response must be requested before it is eligible to be cached. This can help in controlling cache efficiency by ensuring that only frequently requested responses are cached. By setting this directive, administrators can define a threshold, n, which indicates that the response will only be stored in the cache after being requested at least n times.

This directive is especially useful in scenarios where a backend can serve dynamic content that may not need to be cached after the first request, allowing NGINX to optimize resource usage for frequently accessed resources while minimizing unnecessary caching of rarely requested responses. Thus, setting a higher value for n could lead to better cache quality but may increase latency for first-time requests. Conversely, a lower value could result in a more comprehensive cache but might lead to excess storage of less useful data.

In practice, the optimal value for n should be determined based on user traffic patterns and the specific use case for the application being proxied. Proper tuning of this directive can significantly enhance performance and response times in high-traffic environments.

Config Example

location / {
    ajp_pass tomcats;
    ajp_cache on;
    ajp_cache_zone my_cache;
    ajp_cache_min_uses 5;
}

Setting n too high may lead to increased load times for less popular content, as responses will not be cached until they have been requested enough times.

If caching is enabled but ajp_cache_min_uses is set to 1, it may lead to caching less frequently accessed but still important responses.

← Back to all directives