[varnish] Re: [varnish] Re: Handling of cache-control

Bedis 9 bedis9 at gmail.com
Wed Jan 20 10:19:24 CET 2010


Hi,

Netcache devices had the X-Accel-Cache-Control headers in order to
allow an origin server to setup different Cache-Control parameters for
the cache and the end-user.
The netcache will follow the X-Accel-Cache-Control while the end user
will follow the Cache-Control.

I've a few customer using this, mainly for sports events where "live"
is the key.
They setup X-Accel-Cache-Control to max-age=5 while Cache-Control is
set to no-cache.
That way, all the load generated by thousends of request per second
for "live" stuff is offloaded to the cache layer.
Only a few request goes back to the origin.


I was able to reproduce such behavior with the following inline C:
sub vcl_fetch {
[...]
# Check if X-Accel-Cache-Control exists and follow it
        if (obj.http.X-Accel-Cache-Control) {
C{
        char *cache;
        int max_age = 0;
        cache = VRT_GetHdr(sp, HDR_OBJ, "\026X-Accel-Cache-Control:");
        if(cache) {
                char *s = NULL;
                /* Looking for max-age */
                if (s = strstr(cache, "max-age=")) {
                        s+=8;
                        max_age = strtoul(s, 0, 0);
                        if (max_age) {
                                VRT_l_obj_ttl(sp, max_age);
                        }
                }
        }
}C
       unset obj.http.X-Accel-Cache-Control;
        }

# Cache-Control and Pragma headers preventing caching
        if ((!obj.http.X-Accel-Cache-Control) && (obj.http.Pragma ~
"no-cache" || obj.http.Cache-Control ~ "(no-cache|no-store|private)"))
{
                pass;
        }

}

[...]

}


Maybe it can be useful to somebody else :)

cheers



More information about the varnish-misc mailing list