Caching and performance¶
Know how Sites keeps the caches of its sites apart, and what the servers in front of Drupal and the cache backend must do.
Kept apart per site¶
Drupal's caches need no configuration for Sites:
- Page cache (anonymous visitors): Drupal stores a page under its full URL, hostname included. Every site's hostname, and every sub-site's path prefix, has entries of its own.
- Dynamic page cache and render cache: every entry varies by the site it was built for. A block built on one site is never served on another.
- Saving a site drops what was built from its settings, on the site and on its sub-sites.
How modules declare their per-site cacheability is in Caching.
Reverse proxy and CDN¶
- The cache key must include the hostname. Varnish's built-in hash does; check the cache key of your CDN.
-
Sites picks the site from the hostname that reaches Drupal. A proxy that sends its own hostname to Drupal must pass the visitor's hostname in
X-Forwarded-Host, andsettings.phpmust trust the proxy:$settings['reverse_proxy'] = TRUE; $settings['reverse_proxy_addresses'] = ['10.0.0.5']; -
The hostname of a disabled site answers a plain 404 that Drupal caches. Drupal drops it when the site is enabled. A proxy or CDN that cached the 404 serves it until its entry expires or you purge the hostname.
- Pages of a site with password protection stay
out of the page cache and are sent with
no-cachein theirCache-Controlheader, so shared caches do not store them.
One cache per environment¶
The cached site definitions hold the hostnames and settings of one environment. Two environments on one cache backend, like stage and production on one Redis, serve each other's hostnames and settings. Give every environment its own backend, or, with Redis or Memcache, its own prefix:
$settings['cache_prefix'] = 'stage_';
Many sites¶
- Sites finds the site for a hostname in a cached index. The number of sites adds no work to a request.
- A router rebuild drops the cached pages of every site. Sites rebuilds the router only when the kinds of content the sites hold change, for example when the first site that holds media is created. Creating further sites causes none.