Can someone share their Varnish VCL to set expires in the future

cachevarnish

It seems that a dozen pages exist that tell you how to set your "expires" headers for files, but none that are actually correct.

Right now, my VCL is:

if (req.url ~ "^/media/") {
    set beresp.ttl = 3600s;
    set beresp.http.expires = beresp.ttl;
    set beresp.http.age = "0";
    unset beresp.http.set-cookie;
}

and the browser keeps re-requesting files under /media/ for every request. Can someone share a VCL snippet that will actually tell the browser to cache the object for as long as Varnish does, and not re-request it each time?

My response headers are:

Server Apache/2.2.14 (Ubuntu)
Last-Modified Sun, 15 Aug 2010 22:26:50 GMT
Etag "141d8-184e-48de4364e3e80"
Vary Accept-Encoding
Content-Encoding gzip
Content-Type text/css
Expires 3600.000
Content-Length 1802
Date Mon, 16 Aug 2010 12:16:48 GMT
X-Varnish 808143209 808142052
Age 2184
Via 1.1 varnish
Connection keep-alive

I'm not sure which header is making the browser request the CSS each time, but it does. Help?

Best Answer

How about setting the cache-control header as well?

set beresp.http.cache-control = "max-age = 3600";

If your browser doesn't see that header, it may be inclined to request the object every time. Hope this helps.