]> err.no Git - varnish/commitdiff
Make sure that
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 11 Nov 2008 20:22:05 +0000 (20:22 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 11 Nov 2008 20:22:05 +0000 (20:22 +0000)
set obj.ttl = 0s
means that the object is not hit again by actually using "-1" instead.

This works around the rounding error which otherwise causes the object
to be inside TTL for up to one second - epsilon.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3388 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_vrt.c
varnish-cache/bin/varnishtest/tests/v00023.vtc [new file with mode: 0644]

index 1fb38474bdb29dd03e3f9fe6602977f7c4ff71ef..70099441a137a81b5c67ec63a9b6fc0126c1368d 100644 (file)
@@ -320,9 +320,16 @@ VRT_l_obj_ttl(const struct sess *sp, double a)
        CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);       /* XXX */
        WSP(sp, SLT_TTL, "%u VCL %.0f %.0f",
            sp->obj->xid, a, sp->t_req);
-       if (a < 0)
-               a = 0;
-       sp->obj->ttl = sp->t_req + a;
+       /*
+        * If people set obj.ttl = 0s, they don't expect it to be cacheable
+        * any longer, but it will still be for up to 1s - epsilon because
+        * of the rounding to seconds.
+        * We special case and make sure that rounding does not surprise.
+        */
+       if (a <= 0)
+               sp->obj->ttl = sp->t_req - 1;
+       else
+               sp->obj->ttl = sp->t_req + a;
        EXP_Rearm(sp->obj);
 }
 
diff --git a/varnish-cache/bin/varnishtest/tests/v00023.vtc b/varnish-cache/bin/varnishtest/tests/v00023.vtc
new file mode 100644 (file)
index 0000000..229e444
--- /dev/null
@@ -0,0 +1,31 @@
+# $Id$
+
+test "Test that obj.ttl = 0s prevents subsequent hits"
+
+server s1 {
+       rxreq
+       expect req.url == "/foo"
+       txresp -status 200 -body "1"
+       rxreq
+       expect req.url == "/foo"
+       txresp -status 200 -body "22"
+} -start
+
+varnish v1 -vcl+backend { 
+       sub vcl_hit {
+               set obj.ttl = 0s;
+               restart;
+       }
+} -start
+
+client c1 {
+       txreq -url "/foo"
+       rxresp
+       expect resp.status == 200
+       expect resp.bodylen == 1
+
+       txreq -url "/foo"
+       rxresp
+       expect resp.status == 200
+       expect resp.bodylen == 2
+} -run