function TwigPhpStorageCache::generateKey
Same name in other branches
- 9 core/lib/Drupal/Core/Template/TwigPhpStorageCache.php \Drupal\Core\Template\TwigPhpStorageCache::generateKey()
- 8.9.x core/lib/Drupal/Core/Template/TwigPhpStorageCache.php \Drupal\Core\Template\TwigPhpStorageCache::generateKey()
- 11.x core/lib/Drupal/Core/Template/TwigPhpStorageCache.php \Drupal\Core\Template\TwigPhpStorageCache::generateKey()
File
-
core/
lib/ Drupal/ Core/ Template/ TwigPhpStorageCache.php, line 76
Class
- TwigPhpStorageCache
- Provides an alternate cache storage for Twig using PhpStorage.
Namespace
Drupal\Core\TemplateCode
public function generateKey(string $name, string $className) : string {
if (str_starts_with($name, '{# inline_template_start #}')) {
// $name is an inline template, and can have characters that are not valid
// for a filename. $suffix is unique for each inline template so we just
// use the generic name 'inline-template' here.
$name = 'inline-template';
}
else {
$name = basename($name);
}
// 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 public files path is longer than 120 characters.
// Thus, to always be less than 255, file paths may not be more than 135
// characters long. Using the default PHP file storage class, the Twig cache
// file path will be 124 characters long at most, which provides a margin of
// safety.
$suffix = substr($name, 0, self::SUFFIX_SUBSTRING_LENGTH) . '_';
$suffix .= substr(Crypt::hashBase64($className), 0, self::SUFFIX_SUBSTRING_LENGTH);
// The cache prefix is what gets invalidated.
return $this->templateCacheFilenamePrefix . '_' . $suffix;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.