proxy_cache_min_uses

The `proxy_cache_min_uses` directive sets the minimum number of times a cached response must be used before it is considered valid for serving. — NGINX HTTP Core

proxy_cache_min_uses
httpserverlocation
Синтаксисproxy_cache_min_uses number;
По умолчанию1
Контекстhttp, server, location
МодульNGINX HTTP Core
Аргументы1

Описание

`proxy_cache_min_uses` defines how many times a cached response must be served from the cache before it is deemed valid and can be effectively reused for subsequent client requests. This is particularly useful in scenarios where responses are pre-cached from upstream servers but may require a certain threshold for usability based on characteristics like cache hit rates or load balancing designs. If the cached response has been served fewer times than the specified minimum uses, requests for that content will bypass the cached version, potentially fetching a fresh copy from the upstream server instead. This directive is applicable in various contexts, including `http`, `server`, and `location`, allowing flexible application in different parts of the NGINX configuration. The directive accepts a single integer argument that represents the minimum use threshold. By optimizing the usage threshold, administrators can control cache efficiency and manage server load better, mitigating scenarios that could lead to stale or less reliable content being served from cache.

Пример конфига

location /api {
    proxy_pass http://backend;
    proxy_cache my_cache;
    proxy_cache_min_uses 5;
}

Setting this value too high might lead to unnecessary cache misses, increasing the load on the upstream servers.

Conversely, setting it too low may cause stale data to be served frequently if the backend responses don't change often.