fastcgi_cache_valid

Configures the duration for which valid cached responses are kept in FastCGI caching.

Syntaxfastcgi_cache_valid code time;
Defaultnone
Contexthttp, server, location
Arguments1+

Description

The fastcgi_cache_valid directive defines the time period during which a cached FastCGI response is considered valid, meaning it can be served without querying the backend server again. This directive accepts a time interval and a specific response status code or range of status codes. For example, using fastcgi_cache_valid 200 10m; specifies that a 200 OK response is cached for 10 minutes. You can define multiple lines of this directive to specify different validity periods for different status codes.

It is important to note that the directive should be placed in the appropriate context, such as http, server, or location blocks, and works in conjunction with the fastcgi_cache directive. When a valid cache is served, the fastcgi_cache_bypass directive can be used to bypass the cache conditionally. This allows for great flexibility in ensuring fresh content when necessary, while still benefiting from caching for repetitive requests.

Config Example

fastcgi_cache my_cache;
fastcgi_cache_valid 200 10m;
fastcgi_cache_valid 404 1m;

Ensure fastcgi_cache is defined before using this directive.

Misconfiguration can lead to stale cache responses being served beyond the desired validity period.

Caching errors can occur if status codes are not correctly specified. Feel free to define multiple validity settings for different response codes.

← Back to all directives