uwsgi_cache_revalidate
The `uwsgi_cache_revalidate` directive controls whether NGINX revalidates cached responses with the uWSGI server before serving them.
Description
The uwsgi_cache_revalidate directive is used to manage how cached responses are handled in relation to their freshness. When this directive is enabled, NGINX will issue a revalidation request to the uWSGI server for cached responses that are considered stale. This means that when a cached response's expiration time (defined by the uwsgi_cache_valid directive) has been passed, instead of serving it directly, NGINX will check with the server to ensure that the content is still valid. This can help in situations where content is updated frequently and provides users with the most accurate and up-to-date responses.
This directive can be applied at various contexts including http, server, and location scopes, allowing for flexible caching strategies across different parts of your application. It takes a boolean argument, enabling or disabling the revalidation process. Enabling this directive may add some overhead since it involves an additional request to the uWSGI server however, it ensures data consistency and freshness for end-users.
Using uwsgi_cache_revalidate is particularly useful in environments where application data changes frequently and must reflect those changes without long periods of staleness. It can be paired with other caching directives such as uwsgi_cache, uwsgi_cache_key, and uwsgi_cache_valid to provide a comprehensive caching configuration that suits the needs of the application.
Config Example
uwsgi_cache_path /path/to/cache levels=1:2 keys_zone=my_cache:10m;
location / {
uwsgi_pass my_uwsgi;
uwsgi_cache my_cache;
uwsgi_cache_revalidate on;
uwsgi_cache_valid 200 1h;
}Enabling revalidation may introduce additional latency due to the extra requests made to the uWSGI server.
Ensure your uWSGI application is capable of handling revalidation requests efficiently to avoid performance degradation.
Using uwsgi_cache_revalidate without proper cache invalidation strategies can lead to inconsistent application behavior if not managed correctly.