Skip to content

Cache contexts and tags

Look up the cache contexts and cache tags of the Sites modules: what each one varies by or stands for, and what invalidates it.

Which one to add where is on Caching. {id} is a site's ID (its machine name; default is the hub), {type} an entity type ID.

Contexts

Context Value Module
site The active site's ID. A site switch changes it. With Sites preview, {id}.preview while previewing. Every render cache entry varies by it: Sites adds it to renderer.config required_cache_contexts. sites
sites_negotiated_site The ID of the site the request arrived on. Switches and previews leave it unchanged. sites
sites_context_site On the hub, the site a request acts in: the canonical site of the route's entity, else the route's {site}, else ?site_id. none everywhere else. Its metadata carries the route entity's site_content_membership:{type}:{id} tag. sites
user.sites A hash of the viewer's per-site role assignments and site memberships; anonymous for anonymous users. Its metadata carries user:{uid}, site_role_assignment:user:{uid} and site_content_membership:user:{uid}. sites
environment The current environment's machine name; default when none is detected. environment_context

None of them takes a parameter. The access policy of Sites varies the calculated permissions by site and sites_context_site.

A site object as a cacheable dependency (SitePluginBase) adds the contexts site, languages:language_interface, environment, theme and user.permissions, and the tag site:{id}.

user.sites reads its value from the services tagged sites.user_sites_provider (UserSitesProviderInterface): one for role assignments in sites, one for memberships in sites_content. A module that stores memberships its own way adds a provider.

Tags

Tag Stands for Invalidated when
site:{id} A site's definition and settings. Every response rendered in the site's context carries it. Built by MembershipCacheTags::sitePlugin(). The site entity is saved or deleted, along with the tags of its sub-sites; every site of a site type when the type is saved; a stored config override of the site is written.
site_host:{id} A site's addresses: hostname, aliases, language domains, path prefix. Carried by links to the site from other sites' pages. MembershipCacheTags::siteHost(). The site is created or deleted, or a save changes its status or an address setting; its sub-sites' tags with it.
sites_list The list of sites, the site entity's list tag. Any site entity write; a site type save.
site_config_override_list:{id} A site's stored config overrides. Every configuration read in a site context carries it. SiteConfigOverrideRepositoryInterface::LIST_TAG_PREFIX. A stored override of the site is written or deleted.
site_content_membership:{type}:{id} One entity's memberships. MembershipCacheTags::entity(); account() for a user. A membership row of the entity is written; the site_id field of a SiteIdFieldEntityInterface entity changes. The entity's own tag is invalidated with it.
site_content_membership_site:{id} One site's set of member entities. MembershipCacheTags::site(). A membership row of the site is written, or moved away from it.
site_content_list:{type}:{id} One entity type's content on one site. A view with the cache plugin sites_tag (Tag based, per site) that lists the site's content on its host carries it in place of {type}_list. MembershipCacheTags::siteList(). An entity of the type that belongs to the site is updated or deleted.
site_content_membership_shared:{type} The entities of a shared-pool type (declared with hook_sites_shared_pool_content_entity_types_alter()) that belong to no site and show on every site. MembershipCacheTags::sharedPool(). An entity of the type enters or leaves the pool; an entity in the pool is written.
site_content_relationship_list Any membership. MembershipCacheTags::ANY_MEMBERSHIP. Any membership row write (core's list tag).
site_role_assignment_list Any per-site role assignment. SiteAccessCacheability::ROLE_ASSIGNMENT_TAG. Any assignment write (core's list tag).
site_role_assignment:user:{uid} One account's per-site roles. SiteAccessCacheability::assignmentTag(). An assignment of the account is written.
site_role_assignment:user:{uid}:site:{id} One account's roles on one site. SiteAccessCacheability::siteAssignmentTag(). An assignment of the account on the site is written.
site_content_override:{type}:{id} Which sites override an entity. OverrideCacheTags::entity(). Sites content overrides. An override of the entity is saved, reverted or deleted; an aspect is set or reverted.
site_content_override:{type}:{id}:{site} One site's version of an entity. Responses on routes with an overridable entity carry it. OverrideCacheTags::site(). As above, for that site.
config:system.menu.{menu}__{id} A site's links in a per-site menu. Sites menu. A link of the per-site menu is written (core).

While an override revision is saved, Sites content overrides withholds the entity's own tags, its list and bundle list tags, 4xx-response and the other sites' site_content_list tags from invalidation; it invalidates the two site_content_override tags instead.

Section grants

A site admin section that declares no grant_cache_tags gets SiteAccessCacheability::DEFAULT_GRANT_CACHE_TAGS: config:user_role_list, sites_list and site_role_assignment_list. Declared tags replace them.