diff --git a/lib/Twig/Cache/Filesystem.php b/lib/Twig/Cache/Filesystem.php index c62c7111a2..f3946016af 100644 --- a/lib/Twig/Cache/Filesystem.php +++ b/lib/Twig/Cache/Filesystem.php @@ -29,11 +29,11 @@ public function __construct($directory) /** * {@inheritdoc} */ - public function generateKey($className, $prefix) + public function generateKey($name, $className) { - $class = substr($className, strlen($prefix)); + $hash = hash('sha256', $className); - return $this->directory.'/'.$class[0].'/'.$class[1].'/'.$class.'.php'; + return $this->directory.'/'.$hash[0].'/'.$hash[1].'/'.$hash.'.php'; } /** diff --git a/lib/Twig/Cache/Null.php b/lib/Twig/Cache/Null.php index 4812600e9d..918e4cef33 100644 --- a/lib/Twig/Cache/Null.php +++ b/lib/Twig/Cache/Null.php @@ -19,7 +19,7 @@ class Twig_Cache_Null implements Twig_CacheInterface /** * {@inheritdoc} */ - public function generateKey($className, $prefix) + public function generateKey($name, $className) { return ''; } diff --git a/lib/Twig/CacheInterface.php b/lib/Twig/CacheInterface.php index 390e7b0398..fedd36625e 100644 --- a/lib/Twig/CacheInterface.php +++ b/lib/Twig/CacheInterface.php @@ -23,12 +23,12 @@ interface Twig_CacheInterface /** * Generates a cache key for the given template class name. * + * @param string $name The template name * @param string $className The template class name - * @param string $prefix A template class prefix * * @return string */ - public function generateKey($className, $prefix); + public function generateKey($name, $className); /** * Checks if the cache key exists. diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index f6104c2aff..e675c2f7f6 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -283,7 +283,7 @@ public function getCacheFilename($name) { @trigger_error(sprintf('The %s method is deprecated and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); - $key = $this->cache->generateKey($this->getTemplateClass($name), $this->templateClassPrefix); + $key = $this->cache->generateKey($name, $this->getTemplateClass($name)); return !$key ? false : $key; } @@ -370,7 +370,7 @@ public function loadTemplate($name, $index = null) if ($this->bcGetCacheFilename) { $key = $this->getCacheFilename($name); } else { - $key = $this->cache->generateKey($cls, $this->templateClassPrefix); + $key = $this->cache->generateKey($name, $cls); } if (!$this->cache->has($key) || ($this->isAutoReload() && !$this->isTemplateFresh($name, $this->cache->getTimestamp($key)))) { diff --git a/test/Twig/Tests/EnvironmentTest.php b/test/Twig/Tests/EnvironmentTest.php index 84af47c81b..7d78179aa6 100644 --- a/test/Twig/Tests/EnvironmentTest.php +++ b/test/Twig/Tests/EnvironmentTest.php @@ -156,7 +156,7 @@ public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate() // force compilation $twig = new Twig_Environment($loader = new Twig_Loader_Array(array('index' => '{{ foo }}')), $options); - $key = $cache->generateKey($twig->getTemplateClass('index'), $twig->getTemplateClassPrefix()); + $key = $cache->generateKey('index', $twig->getTemplateClass('index')); $cache->write($key, $twig->compileSource('{{ foo }}', 'index')); // check that extensions won't be initialized when rendering a template that is already in the cache