如何让Varnish从缓存中回答,而不需要去后台



通常我通过Varnish代理请求文件,它会从缓存返回响应,或者为此访问后端
有没有办法从缓存中请求文件,或者在不强制Varnish访问后端的情况下获得404?

下面的测试用例展示了一种可能的方法:

varnishtest "..."
server s1 {
rxreq
txresp -hdr "Cache-Control: s-maxage=60"
} -start
varnish v1 -vcl+backend {
sub vcl_miss {
if (!req.http.X-Warm-Cache) {
return (synth(404));
}
}
} -start
client c1 {
txreq -url "/foo" -hdr "X-Warm-Cache: 1"
rxresp
expect resp.status == 200
txreq -url "/foo"
rxresp
expect resp.status == 200
txreq -url "/bar"
rxresp
expect resp.status == 404
} -run

相关内容

最新更新