wodby / varnish

Varnish docker container image
https://wodby.com/stacks/varnish
MIT License
59 stars 29 forks source link

varnish cache tag invalidation not working with drupal 8. #33

Closed genebobmiller closed 3 years ago

genebobmiller commented 3 years ago

Using the Varnish Purge module with the following headers set:

Cache-Tags: [invalidation:expression] X-VC-Purge-Key:

never seems to invalidate.

I believe this is due to the wodby image vcl looking for the Cache-Tags header when drupal is returning X-Drupal-Cache-Tags. The attached patch seems to fix the issue.

diff --git a/templates/includes/purge.vcl.tmpl b/templates/includes/purge.vcl.tmpl
index e30e2b1..aef0de8 100755
--- a/templates/includes/purge.vcl.tmpl
+++ b/templates/includes/purge.vcl.tmpl
@@ -48,8 +48,8 @@ sub vcl_recv {
         {{ end }}
         {{ end }}

-        if (req.method == "BAN" && req.http.Cache-Tags) {
-            ban("obj.http.Cache-Tags ~ " + req.http.Cache-Tags);
+        if (req.method == "BAN" && req.http.X-Drupal-Cache-Tags) {
+            ban("obj.http.X-Drupal-Cache-Tags ~ " + req.http.X-Drupal-Cache-Tags);
         }

         if (req.http.X-VC-Purge-Method) {
csandanov commented 3 years ago

Module https://www.drupal.org/project/varnish_purge still uses Cache-Tags header. I believe X-Drupal-Cache-Tags used for debugging. Also see https://www.drupal.org/docs/drupal-apis/cache-api/cache-tags-varnish

genebobmiller commented 3 years ago

Thanks Chingis!

Enabling the Varnish Purger Tag module added the necessary Cache-Tags header.