Skip to content

Commit 50d57a0

Browse files
author
Magento CICD
authored
MAGETWO-64713: [GitHub] [PR] Adds support for purging varnish cache based on an X-Pool header #4106
2 parents 91182c9 + 937ed0e commit 50d57a0

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@ sub vcl_recv {
2626
if (client.ip !~ purge) {
2727
return (synth(405, "Method not allowed"));
2828
}
29-
if (!req.http.X-Magento-Tags-Pattern) {
30-
return (synth(400, "X-Magento-Tags-Pattern header required"));
29+
# To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header
30+
# has been added to the response in your backend server config. This is used, for example, by the
31+
# capistrano-magento2 gem for purging old content from varnish during it's deploy routine.
32+
if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) {
33+
return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required"));
34+
}
35+
if (req.http.X-Magento-Tags-Pattern) {
36+
ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
37+
}
38+
if (req.http.X-Pool) {
39+
ban("obj.http.X-Pool ~ " + req.http.X-Pool);
3140
}
32-
ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
3341
return (synth(200, "Purged"));
3442
}
3543

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,18 @@ sub vcl_recv {
2727
if (client.ip !~ purge) {
2828
return (synth(405, "Method not allowed"));
2929
}
30-
if (!req.http.X-Magento-Tags-Pattern) {
31-
return (synth(400, "X-Magento-Tags-Pattern header required"));
30+
# To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header
31+
# has been added to the response in your backend server config. This is used, for example, by the
32+
# capistrano-magento2 gem for purging old content from varnish during it's deploy routine.
33+
if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) {
34+
return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required"));
35+
}
36+
if (req.http.X-Magento-Tags-Pattern) {
37+
ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
38+
}
39+
if (req.http.X-Pool) {
40+
ban("obj.http.X-Pool ~ " + req.http.X-Pool);
3241
}
33-
ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
3442
return (synth(200, "Purged"));
3543
}
3644

0 commit comments

Comments
 (0)