proxy_cache_revalidate
The `proxy_cache_revalidate` directive controls whether NGINX revalidates cached entries with the origin server before serving them to clients. — NGINX HTTP Core
Описание
When enabled, `proxy_cache_revalidate` causes NGINX to send a conditional request to the upstream server for revalidating cached entries when there is an expired cache. It performs this validation by sending an If-Modified-Since or If-None-Match header with requests, which informs the origin server to check if the cached resource has been modified since it was last fetched. This behavior is particularly useful for ensuring that clients receive the most up-to-date versions of resources when serving cached content. If the upstream server responds that the resource has not changed (HTTP 304 Not Modified), NGINX serves the stale cached version to the client. If the resource has changed, NGINX fetches the new version and updates its cache accordingly. It's important to use this directive with a proper caching strategy to prevent unnecessary requests to the upstream server, particularly if the cache is frequently accessed and resources are less likely to be modified. However, if real-time accuracy is crucial for your application, enabling this directive may help maintain up-to-date content delivery.
Пример конфига
location /example {
proxy_pass http://example_upstream;
proxy_cache my_cache;
proxy_cache_revalidate on;
}Using this directive without a valid caching strategy may lead to high loads on upstream servers due to constant revalidation requests.
Ensure that the upstream server supports conditional requests, or clients may not benefit from this directive.
Remember that enabling this directive may increase response times for the first requests after cache expiration.