How to Debug Drupal Cache Tags and Stale Content Without Clearing All Caches

When an editor updates a node or taxonomy term and the front-end page still shows yesterday’s version, the quickest temptation is to run drush cr. Clearing every cache in production solves the immediate symptom, but it also wipes warm render caches, slows down traffic spikes, and hides the real bug so it happens again next week.

Editorial illustration of Drupal cache tags, contexts, and max-age debugging workflow

Editorial illustration: inspect cacheability headers to separate missing tags, missing contexts, and upstream CDN caching.

Summary

  • Drupal’s Cache API separates when cached output becomes invalid (cache tags), who/what it varies by (cache contexts), and how long it lives (max-age).
  • Enable Drupal’s HTTP cacheability debug headers in a local or staging environment to inspect X-Drupal-Cache-Tags and X-Drupal-Cache-Contexts directly in your browser or curl.
  • If a page does not update after saving an entity, a custom block, Views query, or render array is usually missing the relevant cache tag—or an upstream CDN/Varnish layer is ignoring tag invalidation.
  • Fix the render array’s #cache metadata instead of scheduling full cache rebuilds.

How Drupal’s three cacheability dimensions work

According to the Drupal Cache API documentation, every render array and cacheable response carries three pieces of metadata:

  • Cache tags (tags): Describe data dependencies, such as node:42, taxonomy_term:7, or node_list:article. When entity node:42 is saved, Drupal invalidates every cached item tagged with node:42. See the Drupal cache tags guide for standard entity and list tags.
  • Cache contexts (contexts): Describe request variations, such as url.path, user.roles, or languages:language_interface. If you render per-role content without declaring user.roles, one user’s version leaks to another. We covered context pitfalls in Drupal cache contexts for personalized output.
  • Max-age (max-age): Sets a time-based lifetime in seconds (0 for uncacheable, -1 for permanent until invalidated by tags). Check the Drupal cache max-age documentation for how max-age bubbles up through parent render arrays.

A stale-content bug almost always means one of two things: either the render array forgot to declare the dependency’s cache tag, or an upstream proxy (Varnish or Cloudflare) cached the HTML without purging on that tag.

Step-by-step: Trace a stale page without drush cr

1. Enable debug headers on local or staging

Never turn on verbose debug headers permanently on a public production site if you do not want to expose internal tag names, though they are safe and invaluable in local or staging settings.local.php / services.yml:

parameters:
  http.response.debug_cacheability_headers: true

Once enabled, rebuild cache once on staging so the container picks up the parameter.

2. Inspect response headers with curl

Request the stale URL as an anonymous user and inspect the headers:

curl -I https://staging.example.com/news

Look for three headers:

  • X-Drupal-Cache (Internal Page Cache for anonymous users: HIT or MISS)
  • X-Drupal-Dynamic-Cache (HIT, MISS, or UNCACHEABLE)
  • X-Drupal-Cache-Tags (space-separated list of all tags bubbled into this page)
  • X-Drupal-Cache-Contexts (variation axes)

3. Check whether the missing entity tag is present

Suppose node 42 (an article teaser) was updated, but /news still shows the old title. Check X-Drupal-Cache-Tags on /news:

  • If node:42 or node_list:article is missing, the block, controller, or Twig template rendering that teaser loaded data without bubbling its cacheable metadata.
  • If node:42 IS present, Drupal’s internal cache invalidated properly, which means either a reverse proxy/CDN (like Cloudflare or Varnish) still holds an old copy, or a custom max-age / external API cache is sitting in front of it. For edge caching issues, compare this with purging a stale page on Cloudflare.

4. Attach cacheability metadata properly in custom code

When a custom block or controller queries entities and builds a render array, merge the entity’s cacheable metadata rather than hardcoding strings when possible:

$build = [
  '#markup' => $node->label(),
  '#cache' => [
    'tags' => $node->getCacheTags(),
    'contexts' => ['url.path'],
  ],
];

Or use CacheableMetadata::createFromObject($node)->applyTo($build) so tags, contexts, and max-age all bubble together cleanly. If your custom block lists all published articles, include node_list:article (or node_list) so creating or deleting an article also invalidates the listing.

5. Verify invalidation on staging

  1. Load /news and confirm X-Drupal-Cache: HIT.
  2. Edit and save node 42 without running drush cr.
  3. Reload /news and confirm X-Drupal-Cache: MISS followed by HIT on the next request, with the updated title visible.

Common mistakes

  • Running drush cr via cron to mask stale pages. This turns a targeted invalidation bug into a recurring performance penalty.
  • Setting max-age: 0 on a block to “fix” staleness. For anonymous traffic using Drupal’s Internal Page Cache, max-age: 0 in a child element does not always behave the way developers expect unless page-level kill switches or proper tags are used.
  • Forgetting list tags (node_list:<bundle>). Tagging node:42 handles edits to existing items, but newly created items will not appear in a custom listing unless the bundle list tag is present.
  • Ignoring upstream CDN headers. Even when Drupal invalidates its own cache_page bin, an edge CDN with a long Cache-Control: max-age will keep serving old HTML unless configured with purge integration. For broader cache layer checks, see Drupal cache troubleshooting.

Why this matters

Drupal’s cache tag architecture is one of its strongest performance features: a site can cache pages for months and still reflect an editor’s change in seconds. Taking ten minutes to read X-Drupal-Cache-Tags on staging turns guesswork into a permanent fix.

My Take

Whenever someone tells me “Drupal caching is broken, we need to clear cache every hour,” nine times out of ten it is a single custom block or Twig template missing one CacheableMetadata call—or an edge CDN that is not connected to purge tags. Inspect the headers first; keep drush cr for deployments, not content edits.

Conclusion

Enable http.response.debug_cacheability_headers on staging, inspect X-Drupal-Cache-Tags with curl -I, and verify whether the expected entity or list tag is present. Fix missing #cache metadata in custom render arrays or configure upstream CDN purging so editors see updates immediately without flushing the entire site cache.

Sources