Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't purge static assets in Varnish from Magento #337

Open
joeshelton-wagento opened this issue Dec 7, 2021 · 0 comments
Open

Can't purge static assets in Varnish from Magento #337

joeshelton-wagento opened this issue Dec 7, 2021 · 0 comments

Comments

@joeshelton-wagento
Copy link
Contributor

Preconditions

Default install in developer mode with Varnish enabled and configured properly. Browser cache disabled

Steps to reproduce

  1. Load a page in the browser and ensure Varnish cache has cached static assets like .css, .js
  2. Run bin/magento cache:clean full_page
  3. Load the same page as step 1 and observe the cache behavior on static assets

Expected result

Static assets would have a Varnish cache miss due to full_page cache being previously cleared

Actual result

Static assets are cache hits. (Non-static assets cleared properly.)

Due to the existing VCL section on purging, static assets can't be purged using the Magento application. Only resources with the X-Magento-Tags-Pattern header will ever be purged by the existing conditional. Static assets will never have this header.

    if (req.method == "PURGE") {
        if (!req.http.X-Magento-Tags-Pattern) {
            return (synth(400, "X-Magento-Tags-Pattern header required"));
        }
        ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
        return (synth(200, "Purged"));
    }

Recommend adding something that clears all cached resources when a "purge all" request is made by Magento.

    if (req.method == "PURGE") {
        if (!req.http.X-Magento-Tags-Pattern) {
            return (synth(400, "X-Magento-Tags-Pattern header required"));
        }
        if (req.http.X-Magento-Tags-Pattern == ".*") {
            ban("req.url ~ /");
        } else {
            ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
        }
        return (synth(200, "Purged"));
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Backlog
Ready for Grooming
Development

No branches or pull requests

1 participant