Skip to content

Commit

Permalink
[Templating] optimized the cache directory of CacheLoader (especially…
Browse files Browse the repository at this point in the history
… if there is a large number of templates)
  • Loading branch information
fabpot committed Feb 2, 2010
1 parent 6ef1f07 commit 94f6e78
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Symfony/Components/Templating/Loader/CacheLoader.php
Expand Up @@ -41,11 +41,6 @@ public function __construct(Loader $loader, $dir)
$this->loader = $loader;
$this->dir = $dir;

if (!file_exists($dir))
{
mkdir($dir, 0777, true);
}

parent::__construct();
}

Expand All @@ -61,7 +56,10 @@ public function load($template, array $options = array())
{
$options = $this->mergeDefaultOptions($options);

$path = $this->dir.DIRECTORY_SEPARATOR.md5($template.serialize($options)).'.tpl';
$tmp = md5($template.serialize($options)).'.tpl';
$dir = $this->dir.DIRECTORY_SEPARATOR.substr($tmp, 0, 2);
$file = substr($tmp, 2);
$path = $dir.DIRECTORY_SEPARATOR.$file;

if ($this->loader instanceof CompilableLoaderInterface)
{
Expand Down Expand Up @@ -90,6 +88,11 @@ public function load($template, array $options = array())
$content = $this->loader->compile($content);
}

if (!file_exists($dir))
{
mkdir($dir, 0777, true);
}

file_put_contents($path, $content);

if (null !== $this->debugger)
Expand Down

0 comments on commit 94f6e78

Please sign in to comment.