Low-latency enterprise platforms require caching configurations that are verified on the developer's workstation, not discovered in production. Mirroring your Varnish edge locally with DDEV makes cache behaviour testable, reviewable and boring, which is exactly what you want.
Local edge configuration with DDEV
Matching edge caching across environments is a classic source of "works on my machine" bugs. DDEV's Varnish add-on puts a Varnish container in front of your web container so your local topology matches production:
ddev add-on get ddev/ddev-varnish
ddev restart
# Your primary URL is now served through Varnish;
# the add-on also exposes a way to reach the web container directly
# for side-by-side comparison (see the add-on README).
Commit the generated .ddev configuration and your default.vcl so every engineer runs the same edge rules.
VCL rulesets and granular cache-tag purging
Drupal attaches cache tags to every response (for example node:42 or config:system.menu.main). With a purger such as the Purge and Varnish Purger modules, Drupal sends invalidation requests when content changes. Your VCL decides how to handle them:
acl purge {
"127.0.0.1";
"web"; # DDEV web container
}
sub vcl_recv {
if (req.method == "BAN") {
if (!client.ip ~ purge) {
return (synth(403, "Not allowed."));
}
if (req.http.Cache-Tags) {
ban("obj.http.Cache-Tags ~ " + req.http.Cache-Tags);
return (synth(200, "Ban added."));
}
return (synth(400, "Cache-Tags header missing."));
}
}
sub vcl_deliver {
# Keep tags locally for debugging; strip them in production.
set resp.http.X-Cache = (obj.hits > 0) ? "HIT" : "MISS";
}
This lets the edge clear only the fragments affected by an update, keeping origin load close to zero while serving fresh content immediately.
Debugging cache behaviour
When a page refuses to cache, or refuses to clear, inspect it from the outside first, then from inside Varnish:
# Is it a HIT or MISS, and why?
curl -sI https://mysite.ddev.site | grep -iE 'x-cache|age|cache-control|set-cookie'
# Watch BAN requests arrive in real time
ddev exec -s varnish varnishlog -g request -q 'ReqMethod eq "BAN"'
# List active bans
ddev exec -s varnish varnishadm ban.list
Set-Cookie or a session started for anonymous users. Check response headers before you blame the VCL.A checklist before merging cache changes
- Anonymous pages return
HITon the second request. - Editing a node clears exactly the pages that display it.
- Authenticated traffic bypasses the cache.
Cache-Tagsand debug headers are stripped in production VCL.
Need help tuning a high-traffic platform? Our Drupal performance engineers can review your stack.