fastcgi_cache_revalidate

The 'fastcgi_cache_revalidate' directive controls whether NGINX will revalidate cached FastCGI responses.

Syntaxfastcgi_cache_revalidate on | off;
Defaultoff
Contexthttp, server, location
Argumentsflag

Description

The 'fastcgi_cache_revalidate' directive in NGINX allows for finer control over the revalidation of cached responses from FastCGI backends. When this directive is set to 'on', NGINX will issue conditional requests using the 'If-Modified-Since' or 'If-None-Match' headers based on the cached content. This ensures that if the content has changed at the backend, the updated response will be returned to the client accordingly. This behavior helps keep cached content fresh while minimizing unnecessary backend requests, which can enhance performance in environments with dynamic content that does not change frequently.

In contrast, when set to 'off', NGINX will serve cached responses without querying the backend for updates, which can lead to serving stale content if the underlying data has changed. The directive can be particularly useful when dealing with content that has an unpredictable update frequency, as it strikes a balance between serving cached content and ensuring that users receive the most recent version of responses without losing the efficiency advantages of caching.

Config Example

http {
    fastcgi_cache_path /var/cache/nginx/fastcgi_tmp levels=1:2 keys_zone=my_cache:10m;

    server {
        location /fastcgi {
            include fastcgi_params;
            fastcgi_pass backend;
            fastcgi_cache my_cache;
            fastcgi_cache_revalidate on;
        }
    }
}

Ensure that your backend FastCGI application supports conditional GET requests for this directive to be effective.

Using this directive with very frequently changing content may result in excessive backend requests, negating cache benefits.

← Back to all directives