Caching/Headers question

Hugo Cisneiros (Eitch) hugo.cisneiros at
Mon Nov 21 15:54:44 CET 2011

On Sun, Nov 20, 2011 at 4:10 PM, Jo Galara <jogalara at> wrote:

> I got the following setup (on a Debian Squeeze 64-bit machine): Internet
> <-> Varnish <-> Apache
> What I want to achieve is that Varnish forwards all requests from the
> Internet to the Apache backend (if its not in the cache), uses the
> headers from the backend to choose whether or not and how long to cache
> the file and then send the file to the browser with the _same_ headers
> it got from the from the backend.

In vcl_fetch you have all the headers available with beresp.http.<header>.
You can set the TTL based on a header. For example:

if (beresp.http.X-Cache-Time) {
  beresp.ttl = beresp.http.X-Cache-Time;
  return (deliver);
} else
  # default cache time - 30 minutes
  beresp.ttl = 30m;

This way, backend must return the X-Cache-Time with something like "30s",
"1m" or anything varnish understands (no cache at all would be "0s").

If you don't unset the header on vcl_deliver, varnish will deliver the
exact headers received on beresp.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the varnish-misc mailing list