influencing beresp.cacheable on the backend

Tollef Fog Heen tfheen at varnish-software.com
Mon Apr 19 08:22:23 CEST 2010


]] David Birdsong 

| How can I influence bereps.cacheable in a backend such that it will
| evaluate to False?
|
| I set Expires and Cache-Control in the backend, this is what the
| backend generates:
| HTTP/1.1 200 OK
| Server: nginx/0.7.65
| Date: Mon, 12 Apr 2010 21:48:25 GMT
| Content-Type: image/gif
| Content-Length: 43
| Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT
| Connection: close
| Expires: Thu, 01 Jan 1970 00:00:01 GMT
| Cache-Control: no-cache
| 
| From the man page:
| """
| A response is considered cacheable if it is valid (see above), the
| HTTP status code is 200, 203, 300, 301, 302, 404 or 410 and it has a
| non-zero time-to-live when Expires and Cache-Control headers are taken
| into account.
| """

The documentation is wrong for 2.1.0, it's correct for 2.0.x.  I'm sorry
the docs were wrong, I've updated them now.

| And yet this object is getting cached in varnish.  Here is my vcl_fetch:

You can set beresp.cacheable based on the TTL, something like this
should work:

sub vcl_fetch {
    if (beresp.ttl < 1s) {
	set beresp.cacheable = false;
    }
}

-- 
Tollef Fog Heen
Varnish Software
t: +47 21 54 41 73




More information about the varnish-misc mailing list