srcache_store_no_store
`srcache_store_no_store` 指令控制是否应根据 `Cache-Control` 头中的 'no-store' 指令将响应存储在透明子请求缓存中。
Transparent subrequest-based caching layout for arbitrary NGINX locations
·
httpserverlocation
语法srcache_store_no_store on | off;
默认值off
上下文http, server, location
参数flag
说明
srcache_store_no_store 指令用于 NGINX 中的 HTTP、server 和 location 块上下文,特别是与由 ngx_srcache 模块提供的基于透明子请求的缓存机制一起使用。当该指令设置为 'on' 时,它指示 NGINX 在 HTTP 响应中尊重 'no-store' 缓存控制指令。也就是说,如果响应包含 'Cache-Control: no-store' 头,NGINX 将不会将该响应存入缓存,即便其他配置可能允许缓存。相反,如果设置为 'off',NGINX 将忽略 'no-store' 指令,允许这些响应被缓存,这可能导致原本不应存储的敏感或动态内容被缓存。
因此,该指令成为确保某些被视为敏感或经常变化的数据不会被意外缓存的关键机制,从而遵循有关应缓存内容的 HTTP 缓存规范。通过确保遵守源服务器的缓存指令,它在维护缓存数据的完整性和隐私方面发挥重要作用。在需要数据隐私或频繁变化响应准确性的环境中,妥善使用该指令可以帮助避免缓存问题。
配置示例
location /api {
srcache_store_no_store on;
srcache_fetch my_cache;
}
location /public {
srcache_store_no_store off;
srcache_fetch my_cache;
}⚠
确保该指令仅在预期的上下文中设置;放错位置可能导致意外的缓存行为。
⚠
在高流量的位置设置 srcache_store_no_store on 可能会导致在许多响应包含 'Cache-Control: no-store' 的情况下显著降低缓存效率。
⚠
注意上游服务器的缓存指令可能与此设置冲突,从而导致期望行为出现问题。