vmod_xkey
I suggest you use the vmod_xkey
for that. It's an open source Varnish module that performs tag-based invalidation. You can download the source code from https://github.com/varnish/varnish-modules.
However, you have to compile this module from source.
One you have successfully installed the VMOD, you can find the API here: https://github.com/varnish/varnish-modules/blob/master/src/vmod_xkey.vcc.
There are some restrictions though: currently you're tagging responses with the X-Magento-Tags
keyword. This will have to change to the xkey
keyword instead. Hopefully you can make this change in Magento.
Once you've done that, you can call set req.http.n-gone = xkey.purge(req.http.X-Magento-Tags-Pattern);
. The req.http.n-gone
header contains the number of purged items.
vmod_ykey
If vmod_xkey
is too restrictive, you can also use vmod_ykey
, which is the Varnish Enterprise alternative. It offers more flexibility.
See https://docs.varnish-software.com/varnish-cache-plus/vmods/ykey/ for the documentation.
As mentioned in the documentation, you can tag content as follows:
sub vcl_backend_response {
ykey.add_header(beresp.http.X-Magento-Tags);
ykey.add_header(beresp.http.X-Pool);
}
Invalidation can be done through set req.http.n-gone = ykey.purge_header(req.http.X-Magento-Tags-Pattern);
.
DISCLAIMER: Varnish Enterprise is commercial software that requires a license. However, you can use official machine images in the Cloud. This allows you to pay the license on a pay-as-you-go basis. There are Developer Edition images for AWS where lower fees are charged.