我正在学习清漆,我无法理解一些非常基础知识。我创建了一个简单的文件,我希望Varnish存储在缓存中,名为 test.php ,它看起来像这样:
<?php
header("Cache-Control: public, must-revalidate, max-age=0, s-maxage=3600" ); // <-- This should make Varnish cache, right?
?>
<!DOCTYPE HTML>
<html>
<body>
<h1> test </h1>
</body>
</html>
使用这些标头,我希望Varnish将文件存储在缓存中一小时(3600秒)。但是,当我运行 varnishlog -b -o -i TxURL (监控后端请求)时,我可以看到有流量。像这样:
13 BackendClose b default
13 BackendOpen b default 127.0.0.1 57857 127.0.0.1 8080
13 TxURL b /test.php
13 BackendReuse b default
13 TxURL b /test.php
13 BackendReuse b default
13 TxURL b /test.php
如何让Varnish缓存此文件,而不是每次都联系后端?
答案 0 :(得分:0)
我检查了firebug,我在标题中找到了一个Cookie。我不知道为什么有一个cookie,但我用这个更新了我的 vcl 文件:
sub vcl_recv{
if (req.http.cookie){
unset req.http.cookie;
}
}
当请求中存在cookie标头时,默认情况下配置Varnish,以便不缓存。