]> err.no Git - varnish/commitdiff
Start to respect TTL
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 21 Jun 2006 10:21:14 +0000 (10:21 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 21 Jun 2006 10:21:14 +0000 (10:21 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@220 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_fetch.c
varnish-cache/bin/varnishd/cache_pool.c
varnish-cache/bin/varnishd/rfc2616.c

index 7bf6ebd36ed7afae7cce3880174e4aca740053a7..9014fa89283ccf76173fe50842f91f4a0a08a89d 100644 (file)
@@ -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);
index fec882997de8c44c7f5e45df67a78d64f7def825..34e82001ad271f967218bcec9376f3d2cad7144a 100644 (file)
@@ -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:
index 93e7d8e6d867596ebe24152561a679b2ae9245c0..c10c021aacc4c84ed40ec23289f75a89811a7b8a 100644 (file)
@@ -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));
 
index 51bdd944dbf5268305654a94ddad16bea2d95128..189447364d16895759acb639a651a3bd3e917b39 100644 (file)
@@ -8,6 +8,7 @@
 
 #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))
@@ -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);
 }