@@ -57,14 +57,11 @@ Symfony adds automatically:
57
57
.. code-block :: text
58
58
59
59
sub vcl_fetch {
60
- /*
61
- Check for ESI acknowledgement
62
- and remove Surrogate-Control header
63
- */
60
+ // Check for ESI acknowledgement and remove Surrogate-Control header
64
61
if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
65
62
unset beresp.http.Surrogate-Control;
66
63
67
- // For Varnish >= 3.0
64
+ // For Varnish >= 3.0, < 4.0
68
65
set beresp.do_esi = true;
69
66
// For Varnish < 3.0
70
67
// esi;
@@ -79,6 +76,33 @@ Symfony adds automatically:
79
76
}
80
77
}
81
78
79
+ /**
80
+ * For Varnish >= 4.0
81
+ * https://www.varnish-cache.org/docs/4.0/whats-new/upgrading.html#req-not-available-in-vcl-backend-response
82
+ */
83
+ sub vcl_backend_response {
84
+ // Check for ESI acknowledgement and remove Surrogate-Control header
85
+ if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
86
+ unset beresp.http.Surrogate-Control;
87
+
88
+ // For Varnish >= 3.0
89
+ set beresp.do_esi = true;
90
+ // For Varnish < 3.0
91
+ // esi;
92
+ }
93
+ // By default Varnish ignores Cache-Control: nocache
94
+ // (https://www.varnish-cache.org/docs/3.0/tutorial/increasing_your_hitrate.html#cache-control),
95
+ // so in order avoid caching it has to be done explicitly
96
+ if (beresp.http.Pragma ~ "no-cache" ||
97
+ beresp.http.Cache-Control ~ "no-cache" ||
98
+ beresp.http.Cache-Control ~ "private") {
99
+ // https://www.varnish-cache.org/docs/4.0/whats-new/upgrading.html#hit-for-pass-objects-are-created-using-beresp-uncacheable
100
+ set beresp.uncacheable = true;
101
+ set beresp.ttl = 120s;
102
+ return (deliver);
103
+ }
104
+ }
105
+
82
106
.. caution ::
83
107
84
108
Compression with ESI was not supported in Varnish until version 3.0
0 commit comments