当结合使用proxy_cache_background_update on
和proxy_cache_use_stale updating
时,当源站返回错误时,客户端将继续接收过期内容。
后台更新收到源站错误,是否可以刷新缓存项?
我这样做的目的是为了提高响应时间,我不想在源站宕机的情况下继续提供过时的内容。仅当更新缓存时。
发布于 2018-06-16 20:38:11
虽然不是完美的解决方案。我能够通过关闭proxy_cache_use_stale updating
并让源服务器在缓存控制标头中使用stale-while-revalidate
响应来实现此行为。
例如,我的源站返回header:
cache-control: public, max-age=60, stale-while-revalidate=60
当客户端在1分钟后(max-age=60)请求资源时,nginx会在执行后台更新请求的同时,再返回一分钟的过时响应(state- while -revalidate=60)。
如果客户端在2分钟后请求资源,但资源仍然没有更新,它将直接转到源,因此会收到错误。
https://stackoverflow.com/questions/50887670
复制相似问题