Add 'cache_lambda_templates' config option.

Stop caching lambda templates by default, as they are generally too dynamic. Make lambda template caching an explicit opt-in. This will prevent filling cache directories with unusable files, and will actually speed things up the first time any given lambda template is used.

Fixes #180
This commit is contained in:
Justin Hileman
2013-12-14 11:50:57 -08:00
parent 6b7f33c78d
commit 2b5d9e5f39
2 changed files with 70 additions and 3 deletions
+27
View File
@@ -144,6 +144,27 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase
$this->assertInstanceOf($className, $template);
}
public function testLambdaCache()
{
$mustache = new MustacheStub(array(
'cache' => self::$tempDir,
'cache_lambda_templates' => true,
));
$this->assertNotInstanceOf('Mustache_Cache_NoopCache', $mustache->getProtectedLambdaCache());
$this->assertSame($mustache->getCache(), $mustache->getProtectedLambdaCache());
}
public function testWithoutLambdaCache()
{
$mustache = new MustacheStub(array(
'cache' => self::$tempDir
));
$this->assertInstanceOf('Mustache_Cache_NoopCache', $mustache->getProtectedLambdaCache());
$this->assertNotSame($mustache->getCache(), $mustache->getProtectedLambdaCache());
}
/**
* @expectedException Mustache_Exception_InvalidArgumentException
* @dataProvider getBadEscapers
@@ -352,10 +373,16 @@ class MustacheStub extends Mustache_Engine
{
public $source;
public $template;
public function loadTemplate($source)
{
$this->source = $source;
return $this->template;
}
public function getProtectedLambdaCache()
{
return $this->getLambdaCache();
}
}