mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 02:16:41 +00:00
Load templates from cache, even if they have just been compiled
This commit is contained in:
committed by
Fabien Potencier
parent
eeeb1c35f8
commit
ff0abbb7e8
@@ -416,9 +416,17 @@ class Twig_Environment
|
|||||||
$this->writeCacheFile($key, $content);
|
$this->writeCacheFile($key, $content);
|
||||||
} else {
|
} else {
|
||||||
$this->cache->write($key, $content);
|
$this->cache->write($key, $content);
|
||||||
|
$this->cache->load($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
eval('?>'.$content);
|
if (!class_exists($cls, false)) {
|
||||||
|
/* Last line of defense if either $this->bcWriteCacheFile was used,
|
||||||
|
* $this->cache is implemented as a no-op or we have a race condition
|
||||||
|
* where the cache was cleared between the above calls to write to and load from
|
||||||
|
* the cache.
|
||||||
|
*/
|
||||||
|
eval('?>'.$content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -217,7 +217,9 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
|
|||||||
->will($this->returnValue(0));
|
->will($this->returnValue(0));
|
||||||
$loader->expects($this->never())
|
$loader->expects($this->never())
|
||||||
->method('isFresh');
|
->method('isFresh');
|
||||||
$cache->expects($this->never())
|
$cache->expects($this->once())
|
||||||
|
->method('write');
|
||||||
|
$cache->expects($this->once())
|
||||||
->method('load');
|
->method('load');
|
||||||
|
|
||||||
$twig->loadTemplate($templateName);
|
$twig->loadTemplate($templateName);
|
||||||
@@ -245,7 +247,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
|
|||||||
$loader->expects($this->once())
|
$loader->expects($this->once())
|
||||||
->method('isFresh')
|
->method('isFresh')
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
$cache->expects($this->once())
|
$cache->expects($this->atLeastOnce())
|
||||||
->method('load');
|
->method('load');
|
||||||
|
|
||||||
$twig->loadTemplate($templateName);
|
$twig->loadTemplate($templateName);
|
||||||
@@ -271,7 +273,9 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
|
|||||||
$loader->expects($this->once())
|
$loader->expects($this->once())
|
||||||
->method('isFresh')
|
->method('isFresh')
|
||||||
->will($this->returnValue(false));
|
->will($this->returnValue(false));
|
||||||
$cache->expects($this->never())
|
$cache->expects($this->once())
|
||||||
|
->method('write');
|
||||||
|
$cache->expects($this->once())
|
||||||
->method('load');
|
->method('load');
|
||||||
|
|
||||||
$twig->loadTemplate($templateName);
|
$twig->loadTemplate($templateName);
|
||||||
|
|||||||
Reference in New Issue
Block a user