2

There are times when certain pages need to avoid being cached, and they all have the following response header set by the backend:

Cache-Control: no-cache, no-store, must-revalidate, max-age=0

Varnish, however, happily caches these pages nonetheless. Is there something I can add to the config to prevent this? I'm guessing it's something that should go into vcl_deliver or vcl_fetch subroutines, but the documentation isn't very helpful (to me anyway).

Basically looking for something like this but in reverse - should check headers on the response.

Varnish is version 3.0 (no, can't upgrade right now)


Relevant config:

sub vcl_fetch {
    if (req.http.X-Varnish-Use-Cache && beresp.status != 500) {
        set beresp.ttl = 24h;
        set beresp.do_esi = true;
        unset beresp.http.Set-Cookie;
    }

    return (deliver);
}

sub vcl_deliver {
    if(!resp.http.X-Cache) {
        if (obj.hits > 0) {
            set resp.http.X-Cache = "HIT";
        } else {
            set resp.http.X-Cache = "MISS";
        }
    } else {
        if (obj.hits > 0) {
            set resp.http.X-Cache = resp.http.X-Cache + ", HIT";
        } else {
            set resp.http.X-Cache = resp.http.X-Cache + ", MISS";
        }
    }
    set resp.http.X-Flavour = req.http.X-Flavour;
    return (deliver);
}

1 Answer 1

1

Varnish should be honoring the Cache-Control header.

The most likely cause is the return (deliver) in your vcl_fetch which will bypass the default handling that Varnish has, which is what will generally apply the Cache-Control settings and mark the content as not cacheable.

So I would recommend you remove that from the bottom of vcl_fetch.

1
  • I added the vcl_fetch and vcl_deliver configuration to the post. I didn't write it so not sure how different it is from the default behavior. Please take a look.
    – Anonymous
    Sep 12, 2016 at 19:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .