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: 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-TagsandX-Drupal-Cache-Contextsdirectly in your browser orcurl. - 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
#cachemetadata 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 asnode:42,taxonomy_term:7, ornode_list:article. When entitynode:42is saved, Drupal invalidates every cached item tagged withnode:42. See the Drupal cache tags guide for standard entity and list tags. - Cache contexts (
contexts): Describe request variations, such asurl.path,user.roles, orlanguages:language_interface. If you render per-role content without declaringuser.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 (0for uncacheable,-1for permanent until invalidated by tags). Check the Drupal cache max-age documentation for howmax-agebubbles 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:HITorMISS)X-Drupal-Dynamic-Cache(HIT,MISS, orUNCACHEABLE)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:42ornode_list:articleis missing, the block, controller, or Twig template rendering that teaser loaded data without bubbling its cacheable metadata. - If
node:42IS 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 custommax-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
- Load
/newsand confirmX-Drupal-Cache: HIT. - Edit and save node
42without runningdrush cr. - Reload
/newsand confirmX-Drupal-Cache: MISSfollowed byHITon the next request, with the updated title visible.
Common mistakes
- Running
drush crvia cron to mask stale pages. This turns a targeted invalidation bug into a recurring performance penalty. - Setting
max-age: 0on a block to “fix” staleness. For anonymous traffic using Drupal’s Internal Page Cache,max-age: 0in 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>). Taggingnode:42handles 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_pagebin, an edge CDN with a longCache-Control: max-agewill 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.