r220 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Wed Jun 21 12:21:14 CEST 2006


Author: phk
Date: 2006-06-21 12:21:14 +0200 (Wed, 21 Jun 2006)
New Revision: 220

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
   trunk/varnish-cache/bin/varnishd/rfc2616.c
Log:
Start to respect TTL


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-06-21 10:13:53 UTC (rev 219)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-06-21 10:21:14 UTC (rev 220)
@@ -71,6 +71,7 @@
 
 	unsigned		busy;
 	unsigned		len;
+	time_t			ttl;
 
 	char			*header;
 
@@ -105,6 +106,7 @@
 	/* Various internal stuff */
 	struct event		*rd_e;
 	struct sessmem		*mem;
+	time_t			t0;
 };
 
 struct backend {
@@ -200,5 +202,4 @@
 #endif
 
 /* rfc2616.c */
-void RFC2616_Age(struct http *hp, time_t, time_t);
-
+time_t RFC2616_Ttl(struct http *hp, time_t, time_t);

Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-06-21 10:13:53 UTC (rev 219)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-06-21 10:21:14 UTC (rev 220)
@@ -223,7 +223,7 @@
 	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:

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-06-21 10:13:53 UTC (rev 219)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-06-21 10:21:14 UTC (rev 220)
@@ -47,15 +47,15 @@
 	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 @@
 			AZ(pthread_cond_wait(&shdcnd, &sessmtx));
 		}
 		TAILQ_REMOVE(&shd, sp, list);
+		time(&sp->t0);
 		sp->vcl = GetVCL();
 		AZ(pthread_mutex_unlock(&sessmtx));
 

Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/rfc2616.c	2006-06-21 10:13:53 UTC (rev 219)
+++ trunk/varnish-cache/bin/varnishd/rfc2616.c	2006-06-21 10:21:14 UTC (rev 220)
@@ -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 @@
 		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);
 }




More information about the varnish-commit mailing list