Windows (and some encrypted Linux systems) only support 255 characters in a path.
On Windows a requirements error is displayed and installation is blocked if Drupal's root directory path is longer than 100 characters.
To restrict the maximum length while avoid name collisions this change switches to using Crypt::hashBase64() instead of hash('sha256') and take a 25 character substring of the hash and of the Twig template filename.
The 25 is represented by the class constant \Drupal\Core\Template\TwigPhpStorageCache::SUFFIX_SUBSTRING_LENGTH
If the files directory is at 'sites/default/files', and using the default PHP file storage class, the Twig cache file path will be 142 characters long at most, which provides a margin of safety.
The lengths and parts of that path are:
- 30 '/sites/default/files/php/twig/'
- 13
$this->templateCacheFilenamePrefix - 1 '_'
- 25
substr($name, 0, self::SUFFIX_SUBSTRING_LENGTH) - 1 '_'
- 25
substr(Crypt::hashBase64($className), 0, self::SUFFIX_SUBSTRING_LENGTH) - 1 '/'
- 43
Crypt::hmacBase64($name, $this->secret . $directory_mtime) - 4 '.php'
For example:
/sites/default/files/php/twig/584391dd63011_block--search-form-block._-9HtaDVE8pCe5SyzLjs47G6RZ/zr7DyV9p-JKUQ7lXmL2_On-ar9_zOFcess7eZ8sCzO4.php
and
/sites/default/files/php/twig/584391dd63011_views-view-unformatted.ht_75YdpSF8uGOu0W3V8pLvC1dXI/lTHW1DyWYdpziFpU6hRHzI5KDb6xn6b8rMeo0kQFoUw.php