简体   繁体   English

Nginx proxy_cache_background_update在原始错误时清除缓存

[英]Nginx proxy_cache_background_update purge cache on origin error

When using proxy_cache_background_update on in conjunction with proxy_cache_use_stale updating clients will keep receiving stale content when the origin server returns errors. 当结合使用proxy_cache_background_update onproxy_cache_use_stale updating将在源服务器返回错误时继续接收过时的内容。

Is it possible to purge a cache item when the background update receives an error from the origin server? 当后台更新收到来自原始服务器的错误时,是否可以清除缓存项?

My goal with this is to improve response time, I do not want to keep serving stale content when the origin server is down. 我的目标是缩短响应时间,当源服务器关闭时,我不想继续提供过时的内容。 Only when updating cache. 仅在更新缓存时。

While not the perfect solution. 虽然不是完美的解决方案。 I was able to achieve this behavior by turning off proxy_cache_use_stale updating and have the origin server respond with stale-while-revalidate in the cache-control header instead. 我可以通过关闭proxy_cache_use_stale updating来实现此行为,并使原始服务器在cache-control标头中使用stale-while-revalidate进行响应。

For example; 例如; my origin server responds with header: 我的原始服务器响应标头:

cache-control: public, max-age=60, stale-while-revalidate=60

When a client requests the resource after 1min (max-age=60), nginx will return a stale response for another minute (state-while-revalidate=60) while executing a background update request. 当客户端在1分钟后(最大使用期限= 60)请求资源时,nginx将在执行后台更新请求时再返回一分钟的陈旧响应(状态为while-revalidate = 60)。

If a client requests the resource after 2min and it is still not updated, it will go directly to the origin and thus receive an error. 如果客户端在2分钟后请求资源,但仍未更新,它将直接到达源并因此收到错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM