Services
All ServicesDrupal DevelopmentIndustries
Products
AI Smart Quality AssistantPMO AI PlatformAll Products
Portfolio Company
About UsCareersFAQ
Blog Schedule a Consultation
DevOps

Enterprise Caching: Configuring and Debugging Varnish in local DDEV Topologies

Server rack with network cables in a data centre

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
The most common reason pages never hit the cache is a stray Set-Cookie or a session started for anonymous users. Check response headers before you blame the VCL.

A checklist before merging cache changes

  1. Anonymous pages return HIT on the second request.
  2. Editing a node clears exactly the pages that display it.
  3. Authenticated traffic bypasses the cache.
  4. Cache-Tags and debug headers are stripped in production VCL.

Need help tuning a high-traffic platform? Our Drupal performance engineers can review your stack.

3P Technologies Engineering

Our team builds enterprise Drupal platforms, mobile apps and AI products from Amman, Jordan. About us

Keep reading

Related articles

All articles
Abstract visualisation of data being migrated between systemsMigration

Drupal 7 to Drupal 11 Migration: An Enterprise Checklist

Drupal 7 reached end of life in January 2025. If you are still on it, this phase-by-phase checklist covers what enterprise teams need to plan, migrate, validate and launch safely.

Read article
Need an enterprise implementation?

Put our engineers on your project.

Our team specializes in Drupal 11/12 platforms, Varnish performance engineering, multi-level data migrations and AI-powered delivery.