Skip to content

Commit e176347

Browse files
Added config example for Varnish 4.0
1 parent c332063 commit e176347

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

cookbook/cache/varnish.rst

+29-5
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,11 @@ Symfony adds automatically:
5757
.. code-block:: text
5858
5959
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
6461
if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
6562
unset beresp.http.Surrogate-Control;
6663
67-
// For Varnish >= 3.0
64+
// For Varnish >= 3.0, < 4.0
6865
set beresp.do_esi = true;
6966
// For Varnish < 3.0
7067
// esi;
@@ -79,6 +76,33 @@ Symfony adds automatically:
7976
}
8077
}
8178
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+
82106
.. caution::
83107

84108
Compression with ESI was not supported in Varnish until version 3.0

0 commit comments

Comments
 (0)