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);
}
AZ(pthread_cond_wait(&shdcnd, &sessmtx));
}
TAILQ_REMOVE(&shd, sp, list);
+ time(&sp->t0);
sp->vcl = GetVCL();
AZ(pthread_mutex_unlock(&sessmtx));
#include "cache.h"
#include "libvarnish.h"
+#include "heritage.h"
/*--------------------------------------------------------------------
* From RFC2616, 13.2.3 Age Calculations
*
*/
-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))
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);
}