[master] 81913d9 Add obj.age and beresp.age VCL variables
Poul-Henning Kamp
phk at FreeBSD.org
Mon Sep 1 08:45:21 CEST 2014
commit 81913d93d978f45bfa49b65321cb49e4f1e8ad88
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Sep 1 06:45:06 2014 +0000
Add obj.age and beresp.age VCL variables
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 93bbf04..451f516 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -537,6 +537,22 @@ VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, keep, 0)
VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, keep, 0)
/*--------------------------------------------------------------------
+ */
+
+#define VRT_DO_AGE_R(which, sexp) \
+ \
+double \
+VRT_r_##which##_##age(const struct vrt_ctx *ctx) \
+{ \
+ \
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
+ return(ctx->now - sexp.t_origin); \
+}
+
+VRT_DO_AGE_R(obj, ctx->req->objcore->exp)
+VRT_DO_AGE_R(beresp, ctx->bo->fetch_objcore->exp)
+
+/*--------------------------------------------------------------------
* [be]req.xid
*/
diff --git a/bin/varnishtest/tests/r00956.vtc b/bin/varnishtest/tests/r00956.vtc
index 71dc617..a00f001 100644
--- a/bin/varnishtest/tests/r00956.vtc
+++ b/bin/varnishtest/tests/r00956.vtc
@@ -10,12 +10,15 @@ varnish v1 -vcl+backend {
set beresp.http.fooA = beresp.ttl;
set beresp.ttl = 10s;
set beresp.http.fooB = beresp.ttl;
+ set beresp.http.ageA = beresp.age;
}
sub vcl_hit {
set req.http.foo = obj.ttl;
+ set req.http.ageB = obj.age;
}
sub vcl_deliver {
set resp.http.foo = req.http.foo;
+ set resp.http.ageB = req.http.ageB;
}
} -start
@@ -25,6 +28,7 @@ client c1 {
expect resp.bodylen == 40
expect resp.http.fooA == 19.000
expect resp.http.fooB == 10.000
+ expect resp.http.ageA == 4.000
delay 2
txreq
@@ -33,6 +37,8 @@ client c1 {
expect resp.http.fooA == 19.000
expect resp.http.fooB == 10.000
expect resp.http.foo <= 8.000
+ expect resp.http.ageA == 4.000
+ expect resp.http.ageB >= 6.000
delay 2
txreq
@@ -41,4 +47,6 @@ client c1 {
expect resp.http.fooA == 19.000
expect resp.http.fooB == 10.000
expect resp.http.foo <= 6.000
+ expect resp.http.ageA == 4.000
+ expect resp.http.ageB >= 8.000
} -run
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 6e3c91f..ca6f7c9 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -468,7 +468,13 @@ sp_variables = [
( 'backend_response', 'backend_error'),
( 'backend_response', 'backend_error'), """
The object's remaining time to live, in seconds.
- beresp.ttl is writable.
+ """
+ ),
+ ('beresp.age',
+ 'DURATION',
+ ( 'backend_response', 'backend_error'),
+ ( ), """
+ The age of the object.
"""
),
('beresp.grace',
@@ -553,6 +559,13 @@ sp_variables = [
The object's remaining time to live, in seconds.
"""
),
+ ('obj.age',
+ 'DURATION',
+ ( 'hit', ),
+ ( ), """
+ The age of the object.
+ """
+ ),
('obj.grace',
'DURATION',
( 'hit', ),
More information about the varnish-commit
mailing list