honoring browser reload request

Darryl Dixon - Winterhouse Consulting darryl.dixon at winterhouseconsulting.com
Tue Jun 24 22:39:09 CEST 2008

> is the
>following VCL the "correct" solution to support browser shift-reloads to
>get fresh content and actually update the cache?
>sub vcl_hit {
>     if (req.http.Cache-Control ~ "no-cache") {
>         set obj.ttl = 0s;
>         pass;
>     }

Only kind-of; IE and Mozilla send different things with a SHIFT (or CTRL)
+ Reload, we do virtually what you have outlined above, but with a slight

in vcl_recv, we shortcut and send such requests straight to lookup:

    /* Honour Cache-Control: and Pragma: ... */
    if (req.http.Pragma ~ ".*no-cache.*" || req.http.Cache-Control ~
".*no-cache.*") {

...and then in vcl_recv we do similar to you:
    /* Honour Cache-Control: and Pragma: ... */
    if (req.http.Pragma ~ ".*no-cache.*" || req.http.Cache-Control ~
".*no-cache.*") {
        set obj.ttl = 0s;

>As far as I understood vcl(7), this means:
>1. fetch the object from cache (implicit in the fact that we're inside
>2. set ttl to 0s, expiring it (so next requests will fetch new content)
>3. pass to backend (so *this* request see new content)
>Does this do what I expect it to do?

Yes, this configuration does indeed do what you expect (purge the item, go
get a fresh one from the backend)

>Is there a way to avoid hitting the backend twice?

You're only hitting the backend once if you're running the code from vcl_hit

>Is there a way to do that in vcl_recv?

Not really, but see our shortcut above

>(I guess not, since there's no "obj" object available yet, there)
>I guess I could use purge_url(...), except I have virtual hosts and it
>wants a regexp and req.url could contain some special char (could it?).

We tried with purge_url but it was just too hard and didn't want to do
what we expected. We've had good results with our configuration above.

Hope this helps,

Darryl Dixon
Winterhouse Consulting Ltd

More information about the varnish-misc mailing list