Incorrect cache invalidation in suggested default.vcl

Created on 30 June 2022, over 2 years ago

In most suggested Varnish configuration files, cache tag invalidation is performed by this expression:
ban("obj.http.Cache-Tags ~ " + req.http.Cache-Tags);

This is completely incorrect in case of multiple tags sent in one request (and this exactly how Varnish purgers send tags).
For example, if obj.http.Cache-Tags="node_list node:1" and req.http.Cache-Tags="node_list node:1 node:2", there will be no invalidation.
And if obj.http.Cache-Tags="node:123" and req.http.Cache-Tags="node:1", there will be unnecessary invalidation.

We need to split tags by spaces and allow each tag to appear either at line beginning or line end or be surrounded by spaces. The correct expression is
ban("obj.http.Cache-Tags ~ " + regsuball(regsuball(req.http.Cache-Tags, "([^ ]+)( +|$)", "((^|\\s)\1(\\s|$))|"), "\|$", ""));

(maybe it can be simplified, but at least it works properly).

🐛 Bug report
Status

Active

Version

2.0

Component

Miscellaneous

Created by

🇷🇺Russia maximpodorov

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇿New Zealand davidwhthomas

    Thanks for adding this. You are absolutely right. The current ban expression does not support multiple cache tags and also has other spurious matches. I've tested your updated ban expression and it works well.

Production build 0.71.5 2024