Closed mahagr closed 8 years ago
Unfortunately $this->directory
has private access, so I cannot just extend the class either.
I copied the class and used the following code myself:
public function generateKey($name, $className)
{
$hash = hash('sha256', $className . '-' . PHP_VERSION);
return $this->directory.$hash[0].$hash[1].'/'.$hash.'.php';
}
Doing this with PHP_VERSION
is not a good idea as people might generate the cache on PHP 5.4.3 and then deploy this on a PHP 5.4.4 production server, which would invalidate the cache for no reasons as the cache is exactly the same in this case. So, we need to only differentiate the cache when Twig actually generates a different PHP code.
See #2125
Agreed, but see my comment/concern in the pull request.
Many cached PHP template files contain code that is specific to the PHP version you are using. This causes fatal errors for example in test sites, which have multiple different PHP versions installed.
Right now
Twig_Cache_Filesystem
has this code:Should something like
PHP_VERSION
be added to the key, maybe inside the$hash
?