 [ ← blog / drupal ](/) Dec 01, 2026  ·  \#drupal  ·  8 min read 

# Where max-age stops in Drupal

Dynamic Page Cache respects max-age. Internal Page Cache and the Cache-Control header your CDN reads don't. Here's how to keep Dynamic Page Cache working and give pages a real lifetime.



Did you know `max-age` doesn't make it out of Drupal?

A page's `max-age` usually isn't set on purpose. An access check returns a result marked uncacheable. A block's `getCacheMaxAge()` returns `0`. A view uses time-based caching set to one hour. Each of those bubbles up and lowers the `max-age` of the whole response.

Dynamic Page Cache respects that. Then it stops. Internal Page Cache ignores it, and so does the `Cache-Control` header your CDN or reverse proxy reads. Every cacheable page leaves Drupal with the same lifetime, whatever its content declared.

## Know which caches ignore it

A response can be cached in three places after Drupal builds it. Only one of them respects `max-age`.

Dynamic Page Cache caches the page for every user, with personalized parts left as placeholders. It respects `max-age`. A response whose bubbled `max-age` is `0` isn't cached, and an element with `max-age: 0` is placeholdered automatically, because that's one of the default auto-placeholder conditions in `renderer.config`.

Internal Page Cache caches the full response for anonymous users. It doesn't respect `max-age`. Core says so directly in [`PageCache::storeResponse()`](https://git.drupalcode.org/project/drupal/-/blob/main/core/modules/page_cache/src/StackMiddleware/PageCache.php):

```php
// The response passes all of the above checks, so cache it. Page cache
// entries default to Cache::PERMANENT since they will be expired via cache
// tags locally. Because of this, page cache ignores max age.
// - Get the tags from CacheableResponseInterface per the earlier comments.
// - Get the time expiration from the Expires header, rather than the
//   interface, but see https://www.drupal.org/node/2352009 about possibly
//   changing that.

```

The page stays cached until one of its cache tags is invalidated. Content that goes stale because time passed, not because something was saved, is never cleared.

The `Cache-Control` header that your CDN, reverse proxy, and browsers read doesn't respect it either. `FinishResponseSubscriber::setResponseCacheable()` builds it from one global setting, the "Browser and proxy cache maximum age" on the Performance page:

```php
$max_age = $this->config->get('cache.page.max_age');
$response->headers->set('Cache-Control', 'public, max-age=' . $max_age);

```

That setting defaults to `0`, which sends `no-cache` on every page. Once you raise it, a page with an element that declared `max-age: 0` still goes out as `public`, cacheable for the full site-wide lifetime.

## Keep Dynamic Page Cache when a page can't be cached

When something on a page really is uncacheable, the goal is to skip Internal Page Cache without losing Dynamic Page Cache. Dynamic Page Cache already handles `max-age: 0` well. It caches the page and keeps the uncacheable part as a placeholder, rendered fresh on every request.

Internal Page Cache decides what to store by checking response policies. A policy tagged `page_cache_response_policy` can deny a response based on its bubbled cacheability:

```php
namespace Drupal\mymodule\PageCache;

use Drupal\Core\Cache\CacheableResponseInterface;
use Drupal\Core\PageCache\ResponsePolicyInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

final class DenyUncacheableResponses implements ResponsePolicyInterface {

  public function check(Response $response, Request $request): ?string {
    if ($response instanceof CacheableResponseInterface
      && $response->getCacheableMetadata()->getCacheMaxAge() === 0) {
      return self::DENY;
    }
    return NULL;
  }

}

```

```yaml
services:
  Drupal\mymodule\PageCache\DenyUncacheableResponses:
    tags:
      # Only Internal Page Cache. Dynamic Page Cache keeps working.
      - { name: page_cache_response_policy }

```

`FinishResponseSubscriber` checks the same policies before it builds `Cache-Control`, so a denied response also goes out as `must-revalidate, no-cache, private`. Your CDN skips it too.

You don't have to write this yourself. The [Cache Control Override](https://www.drupal.org/project/cache_control_override) module ships the same policy, along with the header fix in the next section.

There's a catch. Any element with `max-age: 0` now turns off Internal Page Cache on every page it appears on. One block like that in a site-wide region makes the whole site uncacheable for anonymous users. Check `X-Drupal-Cache` on a few key pages after you add it.

Core's own tools for this, the `no_cache` route option and the `page_cache_kill_switch` service, go further. Both are also registered as Dynamic Page Cache policies, so they turn off both caches for the page. Use `no_cache` when a whole route really is live. Avoid triggering the kill switch from a block, because every page that block appears on loses Dynamic Page Cache too.

## Give the page a real lifetime

Skipping the cache is still the blunt fix. Take an "Upcoming events" block. Events should drop off the list once they start, and no cache tag changes when that happens, but the start time is known. The block's `max-age` should be the number of seconds until the next event starts:

```php
return [
  '#theme' => 'item_list',
  '#items' => $this->upcomingEvents->titles(),
  '#cache' => [
    'tags' => ['node_list'],
    // Valid until the next event starts and drops off the list.
    'max-age' => $this->upcomingEvents->secondsUntilNextStart(),
  ],
];

```

Nothing past Dynamic Page Cache sees that number. Two things need to change: the `Cache-Control` header your CDN reads, and how long Internal Page Cache keeps the page.

Cache Control Override handles the header. It sets `Cache-Control: max-age` from the response's bubbled `max-age`, clamped to a minimum and maximum you configure. It only rewrites responses core already marked `public`, so the "Browser and proxy cache maximum age" has to be above `0` first. Pages with a permanent `max-age` keep that global value.

What the module doesn't touch is Internal Page Cache's lifetime, and that undoes the header fix. When the next event starts and the CDN's copy expires, the CDN asks Drupal for a fresh one. Internal Page Cache still has the page stored permanently, so it hands back the same response. The CDN caches it again, and the page doesn't change until a cache tag clears it.

If your site sits behind a CDN or reverse proxy, [Drupal's documentation](https://www.drupal.org/docs/administering-a-drupal-site/internal-page-cache) says you can safely disable Internal Page Cache. The CDN already serves cached pages to anonymous users. Without Internal Page Cache, Dynamic Page Cache is the first cache behind the CDN. It respects `max-age`, so the module is all you need.

If you keep Internal Page Cache, it does read one header. The core comment above says it gets the expiration time from `Expires`. If a response has an `Expires` date in the future, the page is cached until then. A small response subscriber can set it from the bubbled `max-age`:

```php
namespace Drupal\mymodule\EventSubscriber;

use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Cache\CacheableResponseInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

final class MaxAgeExpiresSubscriber implements EventSubscriberInterface {

  public function __construct(
    private readonly TimeInterface $time,
  ) {}

  public static function getSubscribedEvents(): array {
    // Run after HtmlResponseSubscriber renders placeholders, so their
    // max-age is included.
    return [KernelEvents::RESPONSE => ['onResponse', -10]];
  }

  public function onResponse(ResponseEvent $event): void {
    $response = $event->getResponse();
    if (!$response instanceof CacheableResponseInterface) {
      return;
    }
    $max_age = $response->getCacheableMetadata()->getCacheMaxAge();
    // Permanent (-1) keeps core's behavior. Uncacheable (0) is the response policy's job.
    if ($max_age <= 0) {
      return;
    }
    // Internal Page Cache reads Expires, not max-age.
    $response->setExpires(new \DateTimeImmutable('@' . ($this->time->getRequestTime() + $max_age)));
  }

}

```

```yaml
services:
  Drupal\mymodule\EventSubscriber\MaxAgeExpiresSubscriber:
    arguments: ['@datetime.time']
    tags:
      - { name: event_subscriber }

```

With both in place, when the CDN comes back for a fresh copy, Internal Page Cache has one to give it.

This isn't a new trick. Lullabot described the same approach in [Common max-age Pitfalls When Working with Drupal's Page Cache](https://www.lullabot.com/articles/common-max-age-pitfalls-with-drupal-cache) back in 2019. The [Page Cache Max Age Bubbling](https://www.drupal.org/project/page_cache_max_age_bubbling) module packages it up, though it only has a dev release so far.

This applies to every cacheable response on the site. Any element with a short `max-age` now shortens the lifetime of every page it appears on. That's the behavior `max-age` is supposed to have, but expect pages to be rebuilt more often than they were.

Treat the subscriber as a stopgap. Once [\#2352009](https://www.drupal.org/node/2352009) lands, page cache should read the bubbled `max-age` itself, and you can delete it.

## Where this is headed

The real fix is [\#2352009](https://www.drupal.org/node/2352009), "Bubbling of elements' max-age to the page's headers and the page cache." It's still open. The hard part isn't the code. It's backward compatibility: anything in core or contrib that sets `max-age: 0` today would make pages uncacheable the moment page cache started respecting it.

**Update (December 1, 2026):** [Berdir](https://www.drupal.org/u/berdir) pointed out that #2352009 is down to one blocker, [\#3447821](https://www.drupal.org/project/drupal/issues/3447821) "Stacked caches result in max-age drift in caches," which is RTBC. The code is considered ready. What's left is the backward-compatibility toggle, likely an opt-out for a minor release before the default flips. If you're on Drupal 11.4 or later, there's a snapshot patch on #2352009 you can try instead of the `Expires` subscriber.

Until it lands, Internal Page Cache keeps a page until a cache tag clears it or an `Expires` date passes, and the `Cache-Control` header carries the global default. The `max-age` your render arrays declare stops at Dynamic Page Cache.

The response caching chapter of [Understanding Drupal: A Complete Guide to Caching Layers](https://leanpub.com/understanding-drupal-complete-guide-caching-layers) goes deeper on both page caches and cache tags.

 

  ![](/themes/custom/mglaman/images/headshot.webp)Thanks for reading

I write about Drupal, PHP, and the quiet infrastructure behind large sites — caching, config, and testing. New posts land every week or two.

 [Subscribe via RSS →](/rss.xml) [About me →](/about-me) 

 



 

  [← Older

EvolveDigital NYC 2026: agents as audience, agents as builders

 ](/blog/evolvedigital-nyc-2026-agents-audience-agents-builders)