Dynamic Page Cache in Drupal stores the complete page response for authenticated users while respecting cache tags, contexts, and max-age. It improves performance by reusing page output for different user variations and works together with Render Cache and Lazy Builders to deliver fast, personalized experiences.
Dynamic Page Cache is one of Drupal core's most powerful performance features.
It stores the entire page response for authenticated users, while still respecting personalization such as:
- user roles
- language
- permissions
- URL parameters
Think of it like this:
Drupal builds a smart version of the page for each relevant variation and reuses it whenever possible.
This allows logged-in users to receive fast pages without rebuilding everything on every request.
Core Concept
Page Cache is mainly for anonymous users.
Dynamic Page Cache extends this concept to authenticated users.
Basic flow:
Authenticated Request
↓
Check Dynamic Page Cache
↓
Cache HIT → Return Full Cached Page
↓
Cache MISS → Build Page → Store → Return
Why Dynamic Page Cache Matters
Without Dynamic Page Cache:
- every logged-in request rebuilds the full page
- many database queries are executed
- performance drops significantly
With Dynamic Page Cache:
- most page output is reused
- only truly dynamic fragments are rebuilt
- authenticated performance improves dramatically
Dynamic Page Cache Architecture
Authenticated User
↓
CDN / Reverse Proxy
↓
Drupal Dynamic Page Cache
↓
Render Cache
↓
Database / Services
Real Project Example (Enterprise Dashboard)
On a government intranet site:
- thousands of authenticated users accessed dashboards
- pages contained Views, blocks, and menus
- content varied by role and language
Dynamic Page Cache stored page variants using cache contexts.
Result:
- response time dropped from 2.5s to under 400ms
- server load decreased significantly
- user experience improved dramatically
Page Cache vs Dynamic Page Cache
| Feature | Page Cache | Dynamic Page Cache |
|---|---|---|
| Primary Users | Anonymous | Authenticated |
| Personalization Support | Limited | Yes |
| Uses Cache Contexts | Minimal | Extensive |
| Full Page Cached | Yes | Yes |
Relationship to Render Cache
Dynamic Page Cache stores the full response.
Render Cache stores individual components.
Render Cache → Components
Dynamic Page Cache → Full page for authenticated users
Page Cache → Full page for anonymous users
Cacheability Metadata Still Applies
Dynamic Page Cache depends on:
- cache tags
- cache contexts
- max-age
If a child render array has:
$build['#cache']['max-age'] = 0;
The page may not be cached.
Decision Framework
Use Dynamic Page Cache when:
- users are authenticated
- content is mostly cacheable
- output varies by role, language, or URL
Avoid disabling it unless:
- debugging a cache issue
- highly dynamic content cannot be isolated
Developer Example
$build['#cache'] = [
'tags' => ['node:42'],
'contexts' => ['user.roles', 'languages:language_interface'],
'max-age' => 3600,
];
This allows Drupal to create safe page variants.
Dynamic Content with Lazy Builders
For personalized fragments:
$build['welcome'] = [
'#lazy_builder' => ['my_module.service:getGreeting', [$uid]],
'#create_placeholder' => TRUE,
];
This keeps the page cacheable while rendering the dynamic part separately.
Platform / DevOps Layer
In enterprise environments:
cache_dynamic_page_cachebin stores entries- Redis is commonly used as backend
- CDN caches public responses
- CI/CD should avoid unnecessary full cache rebuilds
Redis example:
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.redis';
Response Headers
Common headers:
X-Drupal-Dynamic-Cache: HIT
X-Drupal-Dynamic-Cache: MISS
These indicate whether Dynamic Page Cache was used.
Debugging Dynamic Page Cache
Useful tools:
curl -I https://example.com
Check:
X-Drupal-Dynamic-CacheCache-Control- cache contexts in render arrays
Other tools:
- Webprofiler
- Kint / dpm()
- Drush cache inspection
Performance Considerations
Best practices:
- keep cache contexts minimal
- use
user.rolesinstead ofuserwhen possible - isolate dynamic content with lazy builders
- avoid
max-age = 0
Common Production Issues
- missing cache contexts → wrong content shown
- too many contexts → cache fragmentation
- personalized blocks disabling page caching
- unnecessary use of
usercontext
SEO & Accessibility Benefits
Although mostly used for authenticated users, Dynamic Page Cache still improves:
- response times
- accessibility for assistive technologies
- backend editorial experience
AI & Future Integration
Future possibilities include:
- AI-driven cache warming for editor dashboards
- predictive caching by user role
- smart personalization strategies
- What is Dynamic Page Cache?
- How is it different from Page Cache?
- Which users benefit from it?
- What response header indicates a cache hit?
- Why are cache contexts critical?
- When should you use Lazy Builders?
Memory Trick
Page Cache = Anonymous Users
Dynamic Page Cache = Authenticated Users
Render Cache = Components
Lazy Builder = Safe Personalization