[master] f8d65d442 param: New uncacheable_ttl for the built-in VCL

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Apr 30 14:49:05 UTC 2025


commit f8d65d44233bbd3c457f1568f53a7edab331c7f4
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed Apr 30 14:55:34 2025 +0200

    param: New uncacheable_ttl for the built-in VCL
    
    This way the hit-for-miss TTL can be updated without requiring a VCL
    reload or a dynamic vcl_beresp_hitmiss override involving a VMOD.

diff --git a/bin/varnishd/builtin.vcl b/bin/varnishd/builtin.vcl
index ed459ce13..271a0217e 100644
--- a/bin/varnishd/builtin.vcl
+++ b/bin/varnishd/builtin.vcl
@@ -255,7 +255,7 @@ sub vcl_beresp_range {
 }
 
 sub vcl_beresp_hitmiss {
-	set beresp.ttl = 120s;
+	set beresp.ttl = param.uncacheable_ttl;
 	set beresp.uncacheable = true;
 	return (deliver);
 }
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index ca4f765ee..24c69cbfc 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -1209,3 +1209,4 @@ PARAM_VAR(send_timeout, DURATION)
 PARAM_VAR(shortlived, DURATION)
 PARAM_VAR(timeout_idle, DURATION)
 PARAM_VAR(transit_buffer, BYTES)
+PARAM_VAR(uncacheable_ttl, DURATION)
diff --git a/bin/varnishtest/tests/c00137.vtc b/bin/varnishtest/tests/c00137.vtc
new file mode 100644
index 000000000..79cc5a6e2
--- /dev/null
+++ b/bin/varnishtest/tests/c00137.vtc
@@ -0,0 +1,34 @@
+varnishtest "Tweak uncacheable_ttl for built-in VCL"
+
+server s1 {
+	loop 3 {
+		rxreq
+		expect req.http.is-hitmiss == false
+		txresp
+	}
+
+	rxreq
+	expect req.http.is-hitmiss == true
+	txresp
+} -start
+
+varnish v1 -cliok "param.set default_ttl 0s"
+varnish v1 -cliok "param.set default_grace 0s"
+varnish v1 -cliok "param.set default_keep 0s"
+varnish v1 -cliok "param.set uncacheable_ttl 1ms"
+varnish v1 -vcl+backend {
+	sub vcl_miss {
+		set req.http.is-hitmiss = req.is_hitmiss;
+	}
+} -start
+
+client c1 -repeat 2 {
+	txreq
+	rxresp
+	delay 0.5
+} -run
+
+varnish v1 -cliok "param.set uncacheable_ttl 1m"
+
+client c1 -run
+server s1 -wait
diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst
index c13402c7d..970ba3656 100644
--- a/doc/sphinx/reference/vcl_var.rst
+++ b/doc/sphinx/reference/vcl_var.rst
@@ -2109,3 +2109,12 @@ param.transit_buffer
 
 	Global parameter transit_buffer.
 
+
+param.uncacheable_ttl
+
+	Type: DURATION
+
+	Readable from: all
+
+	Global parameter uncacheable_ttl.
+
diff --git a/include/tbl/params.h b/include/tbl/params.h
index 9f0f581b2..c613d86c8 100644
--- a/include/tbl/params.h
+++ b/include/tbl/params.h
@@ -484,6 +484,21 @@ PARAM_SIMPLE(
 	/* dyn_def_reason */	"2m"
 )
 
+PARAM_SIMPLE(
+	/* name */	uncacheable_ttl,
+	/* type */	duration,
+	/* min */	"0.000",
+	/* max */	NULL,
+	/* def */	"2m",
+	/* units */	"seconds",
+	/* descr */
+	"The TTL assigned to uncacheable objects by the built-in VCL.",
+	/* flags */	OBJ_STICKY,
+	/* dyn_min_reason */	NULL,
+	/* dyn_max_reason */	NULL,
+	/* dyn_def_reason */	"2m"
+)
+
 PARAM_SIMPLE(
 	/* name */	http1_iovs,
 	/* type */	uint,


More information about the varnish-commit mailing list