uwsgi_cache_valid

Sets the caching duration for responses based on the HTTP status code in NGINX UWSGI caching.

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

Description

The uwsgi_cache_valid directive is used in the context of HTTP, server, and location to define how long specific HTTP response codes should be cached when using UWSGI caching. The directive allows administrators to specify different caching times for various response status codes, which helps optimize content delivery by reducing load on upstream servers. This is particularly useful for dynamic content where some responses are more stable than others.

When configuring this directive, you can provide one or more code and time pairs. Each pair indicates that responses with a specific HTTP status code should be cached for the duration specified by the time parameter. Time values can be specified in seconds, or with suffixes such as 'm' for minutes or 'h' for hours. For instance, 200 10m caches all responses with status 200 for 10 minutes. Responses with a status not defined in the directive will not be cached.

This directive is useful in conjunction with the uwsgi_cache directive, which enables caching for UWSGI responses. By fine-tuning how long different responses are cached, server performance can be improved and bandwidth usage reduced, leading to faster response times for users.

Config Example

uwsgi_cache_valid 200 30m;
uwsgi_cache_valid 404 1m;
uwsgi_cache_valid 500 5m;

Ensure that the specified caching times are appropriate for the content being served, as overly aggressive caching can lead to stale content being served to users.

Responses from upstream servers should be tested to verify that cacheable response codes are indeed being set correctly, as misconfigured backend services can cause unexpected behavior.

← Back to all directives