A new API has been added for services to tag themselves as prewarmable.
To do this, add the cache_prewarmable service tag, and implement PreWarmableInterface.
Example
tags:
- { name: cache_prewarmable }
Plugin managers may also use PreWarmablePluginManagerTrait and several core plugin managers have been adapted to use it.
+ /**
+ * Implements \Drupal\Core\PreWarm\PreWarmableInterface.
+ */
+ public function preWarm(): void {
+ $this->getDefinitions();
+ }
Cache prewarming should not depend on request-specific or request-derived information like the current route, language, or theme, although you could specify these explicitly in a preWarm method as long as persistent and any static caching is accounted for. This is because the context in which a cache can be prewarmed could be prior to routing or via the CLI.