Hi guys,

From RFC2616:

Also, if the response does have a Last-Modified time, the heuristic
   expiration value SHOULD be no more than some fraction of the interval
   since that time. A typical setting of this fraction might be 10%.


Some browsers (at least Firefox -- see https://developer.mozilla.org/en/HTTP_Caching_FAQ) seem to follow this recommendation.

Vernish does not implement it which is fair enough and if someone wanted it they could use an inline C like this:

if ((beresp.ttl == 120s || !beresp.http.Cache-Control) && !beresp.http.Expires &&
            beresp.http.Date && beresp.http.Last-Modified) {
C{
        char *lm = VRT_GetHdr(sp, HDR_BERESP, "\016last-modified:");
        char *d = VRT_GetHdr(sp, HDR_BERESP, "\005date:");

        if (lm && d) {
            time_t lm_t, d_t;
            lm_t = TIM_parse(lm);
            d_t = TIM_parse(d);
            if (d_t > 0 && d_t > lm_t) {
                    double ma = (d_t - lm_t) / 10;
                    VRT_l_beresp_ttl(sp, ma);
                    char buf[16];
                    snprintf(buf, sizeof(buf), "max-age=%d", (int)ma);
VRT_SetHdr(sp, HDR_BERESP, "\016Cache-Control:", buf, vrt_magic_string_end);
            }
        }
}C
}

However I just thought, wouldn't it be better if someone could write something like this:

if (beresp.default_ttl_used && beresp.http.Date && beresp.http.Last-Modified) { beresp.ttl = (ParseDate(beresp.http.Date) - ParseDate(beresp.http.Last-Modified))/10;
    beresp.http.Cache-Control = "max-age="+int(beresp.ttl);
}

What's missing here:

- default_ttl_used flag which should be set to true if no cache validators were found in the backend response (this should be easy to implement with the new exp structure).
- ParseDate() function which could be just a wrapper around TIM_parse().
- int() function which should convert the argument to integer.

All these don't seem very hard to implement and it would be really helpful in many cases. What do you think?


Best regards,

--
Dmitry Panov


_______________________________________________
varnish-dev mailing list
[email protected]
http://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to