scgi_cache_revalidate

指令 `scgi_cache_revalidate` 控制 NGINX 在将缓存的 SCGI 响应提供给客户端之前是否重新验证它们。 — NGINX HTTP Core

scgi_cache_revalidate
httpserverlocation
语法scgi_cache_revalidate on | off;
默认值off
上下文http, server, location
模块NGINX HTTP Core
参数flag

说明

`scgi_cache_revalidate` 指令在 NGINX 中用于 `http`、`server` 或 `location` 块的上下文中。它作为一个开关,用来指定是否在将缓存的响应提供给客户端之前,向 SCGI 服务器重新验证这些响应。当该指令设置为 `on` 时,NGINX 会在每次请求该资源时与后端 SCGI 服务器核验缓存响应的有效性,从而确保客户端接收到最新的数据。如果设置为 `off`,NGINX 将在不检查有效性的情况下提供缓存内容,若服务端内容已更改则可能返回过期的数据。 该指令与其他缓存指令配合使用,例如 `scgi_cache`(定义缓存区域),以及可用来在必要时提供过期内容的 `scgi_cache_use_stale`。`scgi_cache_revalidate` 的主要目的是在后端可能已更新内容且应反映给最终用户的场景中优先保证数据的新鲜度。如果未正确设置该开关,在实现了缓存但未优先执行重新验证的情况下,可能会导致提供过时的内容。

配置示例

scgi_cache_path /tmp/scgi_cache levels=1:2 keys_zone=my_cache:10m;

location /example {
    scgi_pass backend;
    scgi_cache my_cache;
    scgi_cache_revalidate on;
}

将 `scgi_cache_revalidate` 设置为 `off` 可能导致在未经校验的情况下提供过期的内容。

确保 `scgi_cache` 已正确配置,否则此指令将不会生效。