Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.

Commit 5ca631e

Browse files
committed
vrt_var: Make req.ttl and req.grace unsetable
1 parent ac4f5c9 commit 5ca631e

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

bin/varnishd/cache/cache_vrt_var.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,12 +561,24 @@ VRT_r_req_##nm(VRT_CTX) \
561561
return (ctx->req->elem); \
562562
}
563563

564+
#define REQ_VAR_U(nm, elem, val) \
565+
\
566+
VCL_VOID \
567+
VRT_u_req_##nm(VRT_CTX) \
568+
{ \
569+
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
570+
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); \
571+
ctx->req->elem = val; \
572+
}
573+
564574
REQ_VAR_R(backend_hint, director_hint, VCL_BACKEND)
565575

566576
REQ_VAR_L(ttl, d_ttl, VCL_DURATION, if (!(arg>0.0)) arg = 0;)
567577
REQ_VAR_R(ttl, d_ttl, VCL_DURATION)
578+
REQ_VAR_U(ttl, d_ttl, -1)
568579
REQ_VAR_L(grace, d_grace, VCL_DURATION, if (!(arg>0.0)) arg = 0;)
569580
REQ_VAR_R(grace, d_grace, VCL_DURATION)
581+
REQ_VAR_U(grace, d_grace, -1)
570582

571583
VCL_VOID
572584
VRT_l_req_backend_hint(VRT_CTX, VCL_BACKEND be)

bin/varnishtest/tests/b00084.vtc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
varnishtest "unset req.ttl and req.grace"
2+
3+
server s1 {
4+
rxreq
5+
txresp
6+
} -start
7+
8+
varnish v1 -vcl+backend {
9+
sub vcl_recv {
10+
set req.ttl = 0s;
11+
set req.grace = 0s;
12+
unset req.ttl;
13+
unset req.grace;
14+
}
15+
} -start
16+
17+
client c1 -repeat 2 {
18+
txreq
19+
rxresp
20+
expect resp.status == 200
21+
} -run

doc/sphinx/reference/vcl_var.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,13 @@ req.grace
246246

247247
Writable from: client
248248

249+
Unsetable from: client
249250

250251
Upper limit on the object grace.
251252

252253
During lookup the minimum of req.grace and the object's stored
253-
grace value will be used as the object's grace.
254+
grace value will be used as the object's grace. Setting req.grace
255+
to 0s prevents hits on stale objects.
254256

255257

256258
.. _req.hash:
@@ -510,8 +512,10 @@ req.ttl
510512

511513
Writable from: client
512514

515+
Unsetable from: client
513516

514517
Upper limit on the object age for cache lookups to return hit.
518+
Lookups always miss when req.ttl is set to 0s.
515519

516520

517521
.. _req.url:

0 commit comments

Comments
 (0)