Skip to content

Commit 6150231

Browse files
author
Guillaume Quintard
committed
[vcl] don't set TTL to 0
Because of request coalescing, setting the TTL to 0s actually causes backend request queueing, meaning that for one specific object, Varnish will only allow one request at a time. For Varnish 4, set the TTL to 2 minutes, leveraging Hit-for-Pass and Varnish will transform any hit into a pass for the next 2 minutes, preventing queueing. For 5 and 6, the default mechanism is Hit-for-Miss, which works the same as HfP with the added bonus that if the response changes and we we decide to cache it, this will override the HfM TTL. So we can set the TTL for one day.
1 parent def5104 commit 6150231

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

app/code/Magento/PageCache/etc/varnish4.vcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ sub vcl_backend_response {
166166

167167
# cache only successfully responses and 404s
168168
if (beresp.status != 200 && beresp.status != 404) {
169-
set beresp.ttl = 0s;
169+
set beresp.ttl = 120s;
170170
set beresp.uncacheable = true;
171171
return (deliver);
172172
} elsif (beresp.http.Cache-Control ~ "private") {

app/code/Magento/PageCache/etc/varnish5.vcl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,9 @@ sub vcl_backend_response {
166166
}
167167

168168
# cache only successfully responses and 404s
169-
if (beresp.status != 200 && beresp.status != 404) {
170-
set beresp.ttl = 0s;
171-
set beresp.uncacheable = true;
172-
return (deliver);
173-
} elsif (beresp.http.Cache-Control ~ "private") {
169+
if (beresp.status != 200 &&
170+
beresp.status != 404 &&
171+
beresp.http.Cache-Control ~ "private") {
174172
set beresp.uncacheable = true;
175173
set beresp.ttl = 86400s;
176174
return (deliver);

app/code/Magento/PageCache/etc/varnish6.vcl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,10 @@ sub vcl_backend_response {
165165
set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control;
166166
}
167167

168-
# cache only successfully responses and 404s
169-
if (beresp.status != 200 && beresp.status != 404) {
170-
set beresp.ttl = 0s;
171-
set beresp.uncacheable = true;
172-
return (deliver);
173-
} elsif (beresp.http.Cache-Control ~ "private") {
168+
# cache only successfully responses and 404s that are not marked as private
169+
if (beresp.status != 200 &&
170+
beresp.status != 404 &&
171+
beresp.http.Cache-Control ~ "private") {
174172
set beresp.uncacheable = true;
175173
set beresp.ttl = 86400s;
176174
return (deliver);

0 commit comments

Comments
 (0)