magento / magento/magento-cloud-docker

Can't purge static assets in Varnish from Magento

Open
#337 0 comments 0 reactions 0 assignees View on GitHub
Progress: ready for grooming
Dominant language
PHP
Stars
277
Forks
187
PR merge metrics
No merged PRs in 30d

Description

### 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"));
}
```

Contributor guide

Open the contributing guide

Research direction

Start by locating the VCL PURGE handler used by the Magento Varnish configuration and reproduce the issue with `bin/magento cache:clean full_page`. Verify that static assets remain cache hits before the change and become misses after a purge-all request. Done means targeted tag purges still work and a purge-all request clears cached static and non-static resources.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, php
Domain
infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.