1

我们使用 Varnish Cache 作为我们许多客户的前端,并且当任何后端出现问题时,我们会优雅地提供陈旧的内容。

我们现在确实有一个失败的后端,我们想增加宽限期(当它生病时),这是一种可能的情况吗?我尝试在文档中挖掘并一无所获。

清漆 4

4

1 回答 1

1

当生病的后端是常用缓存时,在 Varnish Cache 4.x 中提供过时的内容。您只需要实现自己的vcl_hit子程序。这个想法是使用高宽限值(例如 24 小时)缓存内容,但在后端健康时将宽限限制在一个小时间窗口(例如 10 秒):

sub vcl_hit {
    if (obj.ttl >= 0s) {
        # Normal hit.
        return (deliver);
    }

    # We have no fresh fish. Lets look at the stale ones.
    if (std.healthy(req.backend_hint)) {
        # Backend is healthy. Limit age to 10s.
        if (obj.ttl + 10s > 0s) {
            return (deliver);
        } else {
            # No candidate for grace. Fetch a fresh object.
            return(fetch);
        }
    } else {
        # Backend is sick. Use full grace.
        if (obj.ttl + obj.grace > 0s) {
            return (deliver);
        } else {
            # No graced object.
            return (fetch);
        }
    }
}

如需更多信息,请查看:

于 2016-07-28T06:45:50.107 回答