public function testCacheMiss()
{
+ $file_path = sprintf($this->fixture->template_path(), 'cache_test');
+
$this->cache->expects($this->once())
->method('GetTemplateDataForName')
- ->with($this->equalTo('cache_test'))
+ ->with($this->equalTo($file_path))
->will($this->returnValue(NULL));
- $expected = file_get_contents(sprintf($this->fixture->template_path(), 'cache_test'));
+ $expected = file_get_contents($file_path);
$this->cache->expects($this->once())
->method('StoreCompiledTemplate')
- ->with($this->equalTo('cache_test'),
+ ->with($this->equalTo($file_path),
$this->greaterThan(0),
$this->equalTo($expected));
public function testCacheHit()
{
+ $file_path = sprintf($this->fixture->template_path(), 'cache_test');
+
$expected = 'Cache hit!';
$this->cache->expects($this->once())
->method('GetTemplateDataForName')
- ->with($this->equalTo('cache_test'))
+ ->with($this->equalTo($file_path))
->will($this->returnValue($expected));
// The cache backend is only consulted once.
if (!$this->cache_backend)
return;
- $fetch_templates = array();
+ $fetch_templates = [];
+ $paths_to_names = [];
foreach ($templates AS $name) {
// Do not re-cache templates that have already been cached.
if (isset($this->cache[$name]))
continue;
$tpl_path = $this->_TemplatePath($name);
- $fetch_templates[$name] = filemtime($tpl_path);
+ $fetch_templates[$tpl_path] = filemtime($tpl_path);
+ $paths_to_names[$tpl_path] = $name;
}
$profile = Profiling::IsProfilingEnabled();
$cached_templates = $this->cache_backend->GetMultipleTemplates($fetch_templates);
- foreach ($cached_templates AS $name => $data) {
+ foreach ($cached_templates AS $tpl_path => $data) {
+ $name = $paths_to_names[$tpl_path];
$this->cache[$name] = Template::NewWithCompiledData($name, $data);
if ($profile)
$this->usage[$name] = 0;
if (!$this->cache_backend)
return NULL;
- $data = $this->cache_backend->GetTemplateDataForName($name, filemtime($tpl_path));
+ $data = $this->cache_backend->GetTemplateDataForName($tpl_path, filemtime($tpl_path));
if (!$data)
return NULL;
if ($this->cache_backend) {
$this->cache_backend->StoreCompiledTemplate(
- $name, filemtime($tpl_path), $template->template());
+ $tpl_path, filemtime($tpl_path), $template->template());
}
return $template;