obj.cacheable vs expires headers?

Luc Stroobant lstroobant at gmail.com
Mon Feb 1 21:42:58 CET 2010


Hello list,

I have a vcl-config with a snippet like the one on:
http://varnish-cache.org/wiki/VCLExampleLongerCaching

sub vcl_fetch {
     if (obj.cacheable) {
       unset obj.http.expires;
       set obj.http.cache-control = "max-age = 900";
       set obj.ttl = 2w;
       set obj.http.magicmarker = "1";
     }
}

sub vcl_deliver {
     if (resp.http.magicmarker) {
       /* unset marker and serve it for upstream as new */
       unset resp.http.magicmarker;
       set resp.http.age = "0";
     }
}

We used that in an attempt to override the expires headers from static 
files for a site and keep them in Varnish cache. We don't want to cache 
an dynamic (PHP) page.

At first sight, everything went fine. But once the load rised a bit, we 
noticed that dynamic pages are sometimes cached.
I've been checking the headers and it looks like the expires header for 
dynamic pages is also removed. I don't think the headers from the 
(first) request below should be considerd obj.cacheable  according to 
the definition on http://varnish-cache.org/wiki/VCL
Or did I miss something? Is this a mistake in my config or a possible 
Varnish issue?

Test without the vcl snippet.
PHP page: unmodified headers and not cached, as expected:

HTTP/1.1 200 OK
Server: Apache/2.2.3 (CentOS)
X-Powered-By: PHP/5.2.12
Set-Cookie: SESSbc5f9ce1c97eee1824d1ab6sdfsdfssf70k2hqq7mgo6; 
expires=Wed, 24-Feb-2010 22:58:21 GMT; path=/; domain=removed
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Mon, 01 Feb 2010 19:25:01 GMT
Cache-Control: store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Content-Type: text/html; charset=utf-8
Content-Length: 56194
Date: Mon, 01 Feb 2010 19:25:02 GMT
X-Varnish: 963899298
Age: 0
Via: 1.1 varnish
Connection: close


With the config:
PHP page, Expires header removed and cache-control is set

HTTP/1.1 200 OK
Server: Apache/2.2.3 (CentOS)
X-Powered-By: PHP/5.2.12
Set-Cookie: SESSbc5f9ce1c97eee1824d1ab670ce3057b=91dpgvghvkmonso1; 
expires=Wed, 24-Feb-2010 23:21:04 GMT; path=/; domain=removed
Last-Modified: Mon, 01 Feb 2010 19:47:44 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 59418
cache-control: max-age = 900
Date: Mon, 01 Feb 2010 19:47:48 GMT
X-Varnish: 1790685114
Via: 1.1 varnish
Connection: close
age: 0

I used the same VCL-code in vcl_fetch for both examples and for static 
files, everything works as expected. Any ideas?
(Running on Varnish 2.0.6)

Luc

sub vcl_recv {

     # Add a unique header containing the client address
     remove req.http.X-Forwarded-For;
     set    req.http.X-Forwarded-For = client.ip;

     /* Don't cache accept */
     if (req.http.host ~ "^some.host$") {
       return (pass);
     }

     if (req.url ~ "\.(css|js|jpg|jpeg|gif|ico|png)$") {
     	unset req.http.cookie;
     	lookup;
     }

    /* Never cache php files... */
    if (req.url ~ ".*\.php") {
      return (pass);
    }

    /* ... or Apache server status */
    if (req.url ~ ".*/server-status$") {
      return (pass);
    }
}



More information about the varnish-misc mailing list