drupal-cache-contexts

Define request-dependent cache contexts to vary Drupal render output.

3|5|Updated Jan 8, 2026
One-click install
npx skills add https://github.com/sparkfabrik/sf-awesome-copilot --skill drupal-cache-contexts
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: drupal-cache-contexts
Source: https://github.com/sparkfabrik/sf-awesome-copilot/tree/main/skills/drupal/cache/drupal-cache-contexts
Command: npx skills add https://github.com/sparkfabrik/sf-awesome-copilot --skill drupal-cache-contexts

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Cache contexts define request-dependent cache variations. Analogous to HTTP Vary header.

Core Features & Use Cases

  • Contexts: user, user.roles, user.permissions, url.path, url.query_args:key, languages:language_interface, theme, session
  • Rule: Always use the most specific context possible to prevent cache explosion.
  • Example: Combine roles and language contexts to vary content rendering per user group and locale.

Quick Start

Configure the Drupal render path to apply the most specific cache contexts for your content.

Frequently Asked Questions about drupal-cache-contexts

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What are Drupal cache contexts and when do I need them?

Drupal cache contexts define request-dependent cache variations, functioning like the HTTP Vary header. You need them to vary content rendering by user roles, URL paths, languages, themes, or session data without duplicating output.

How do I prevent cache explosion when combining multiple cache contexts in Drupal?

To prevent cache explosion in Drupal, always apply the most specific cache context possible. Understanding context hierarchy ensures you vary output only by necessary request parameters, avoiding redundant permutations across roles and locales.

How do I vary Drupal render output by user roles and languages?

Vary Drupal render output by combining the user.roles and languages:language_interface cache contexts. This creates distinct cached variations tailored to specific user groups and locales, reducing redundant rendering cycles.

Can I use Drupal cache contexts for per-session and URL query parameters?

Yes, Drupal supports session and url.query_args:key cache contexts for per-session data and specific URL parameters. Apply these precise contexts to vary rendering based on individual session states and dynamic query arguments.

Does configuring Drupal cache contexts require external dependencies?

Configuring Drupal cache contexts requires no external dependencies. It relies on Drupal's native rendering pipeline and built-in contexts like user.permissions, url.path, and theme to manage request-dependent output variations.

Why does my Drupal site render redundant content across different themes?

Redundant rendering across Drupal themes occurs when the theme cache context is not applied. Adding the theme context ensures the system caches distinct output variations for each active theme, preventing unnecessary re-rendering.