Commit bff5c5e9 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Start to respect TTL


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@220 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 940042e5
......@@ -71,6 +71,7 @@ struct object {
unsigned busy;
unsigned len;
time_t ttl;
char *header;
......@@ -105,6 +106,7 @@ struct sess {
/* Various internal stuff */
struct event *rd_e;
struct sessmem *mem;
time_t t0;
};
struct backend {
......@@ -200,5 +202,4 @@ cli_func_t cli_func_config_use;
#endif
/* rfc2616.c */
void RFC2616_Age(struct http *hp, time_t, time_t);
time_t RFC2616_Ttl(struct http *hp, time_t, time_t);
......@@ -223,7 +223,7 @@ FetchSession(struct worker *w, struct sess *sp)
time(&t_resp);
http_Dissect(hp, fd, 2);
RFC2616_Age(hp, t_req, t_resp);
sp->obj->ttl = RFC2616_Ttl(hp, t_req, t_resp);
switch (http_GetStatus(hp)) {
case 200:
......
......@@ -47,15 +47,15 @@ LookupSession(struct worker *w, struct sess *sp)
MD5Final(key, &ctx);
o = hash->lookup(key, w->nobj);
sp->obj = o;
if (o == w->nobj) {
VSL(SLT_Debug, 0, "Lookup new %p %s", o, b);
w->nobj = NULL;
VCL_miss_method(sp);
} else {
if (o != w->nobj && o->ttl > sp->t0) {
/* XXX: wait while obj->busy */
VSL(SLT_Debug, 0, "Lookup found %p %s", o, b);
VCL_hit_method(sp);
return (0);
}
VSL(SLT_Debug, 0, "Lookup new %p %s", o, b);
w->nobj = NULL;
VCL_miss_method(sp);
return (0);
}
......@@ -97,6 +97,7 @@ CacheWorker(void *priv)
AZ(pthread_cond_wait(&shdcnd, &sessmtx));
}
TAILQ_REMOVE(&shd, sp, list);
time(&sp->t0);
sp->vcl = GetVCL();
AZ(pthread_mutex_unlock(&sessmtx));
......
......@@ -8,6 +8,7 @@
#include "cache.h"
#include "libvarnish.h"
#include "heritage.h"
/*--------------------------------------------------------------------
* From RFC2616, 13.2.3 Age Calculations
......@@ -34,13 +35,13 @@
*
*/
void
RFC2616_Age(struct http *hp, time_t t_req, time_t t_resp)
time_t
RFC2616_Ttl(struct http *hp, time_t t_req, time_t t_resp)
{
time_t h_date = 0, h_expires = 0, h_age = 0;
time_t apparent_age = 0, corrected_received_age;
time_t response_delay, corrected_initial_age;
time_t max_age = -1;
time_t max_age = -1, ttl;
char *p;
if (http_GetHdrField(hp, "Cache-Control", "max-age", &p))
......@@ -67,10 +68,19 @@ RFC2616_Age(struct http *hp, time_t t_req, time_t t_resp)
h_expires = TIM_parse(p);
printf("Date: %d\n", h_date);
printf("Recv: %d\n", t_resp);
printf("Expires: %d\n", h_expires);
printf("Age: %d\n", h_age);
printf("CIAge: %d\n", corrected_initial_age);
printf("Max-Age: %d\n", max_age);
ttl = 0;
if (max_age >= 0)
ttl = t_resp + max_age - corrected_initial_age;
if (h_expires && h_expires < ttl)
ttl = h_expires;
if (ttl == 0)
ttl = t_resp + heritage.default_ttl;
printf("TTL: %d (+%d)\n", ttl, ttl - t_resp);
return (ttl);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment