Commit 81913d93 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add obj.age and beresp.age VCL variables

parent bf1fd868
......@@ -536,6 +536,22 @@ VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, grace, 0)
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
*/
......
......@@ -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
......@@ -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', ),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment