0

I'm learning Varnish, and I am having trouble understanding some very basics. I have created a simple file i want Varnish to store in cache, called test.php and it looks like this:

<?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>

With these headers, I expected Varnish to store the file in cache for an hour(3600 seconds). However when i run varnishlog -b -o -i TxURL(To monitor request to backend), i can see that there is traffic. Like this:

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

How can I make Varnish cache this file, and not contact the backend each time?

Pål
  • 958
  • 2
  • 13
  • 18

1 Answers1

0

I checked firebug and i found a Cookie in the header. I have no idea why there is a cookie there, but i updated my vcl file with this:

sub vcl_recv{
    if (req.http.cookie){
            unset req.http.cookie;
    }
}

Varnish is configured by default, to not cache, when there is a cookie header present in the request.

Pål
  • 958
  • 2
  • 13
  • 18