fix huge performance loss when loading cached template with dependencies (should not compile them to check time)

This commit is contained in:
klkvsk 2013-07-10 16:45:42 +04:00
parent 304f44a954
commit 0920284f22
2 changed files with 32 additions and 14 deletions

View File

@ -641,6 +641,23 @@ class Fenom {
$this->_storage[dechex($template->getOptions()).'@'. $template->getName() ] = $template;
}
/**
* @param $tpl
* @param $options
* @return Fenom\Render|null
*/
public function getCachedTemplate($tpl, $options = 0) {
$options |= $this->_options;
$cachePath = $this->_compile_dir . DIRECTORY_SEPARATOR . $this->_getCacheName($tpl, $options);
if (is_file($cachePath)) {
$fenom = $this;
/** @noinspection PhpIncludeInspection */
return include($cachePath);
} else {
return null;
}
}
/**
* Load template from cache or create cache if it doesn't exists.
*
@ -649,19 +666,12 @@ class Fenom {
* @return Fenom\Render
*/
protected function _load($tpl, $opts) {
$cachePath = $this->_compile_dir . DIRECTORY_SEPARATOR . $this->_getCacheName($tpl, $opts);
$useCache = false;
$cached = null;
if (is_file($cachePath)) {
$fenom = $this;
/** @var Fenom\Render $cached */
$cached = include($cachePath);
if (($opts & self::AUTO_RELOAD) !== self::AUTO_RELOAD || $cached->isValid()) {
$useCache = true;
}
$cached = $this->getCachedTemplate($tpl, $opts);
if ($cached && ( !($opts & self::AUTO_RELOAD) || $cached->isValid() )) {
return $cached;
}
return $useCache ? $cached : $this->compile($tpl, true, $opts);
return $this->compile($tpl, true, $opts);
}
/**

View File

@ -141,10 +141,18 @@ class Render extends \ArrayObject {
return false;
}
foreach($this->_depends as $tpl => $time) {
if($this->_fenom->getTemplate($tpl)->getTime() !== $time) {
return false;
// if cached, check time of cache
$cache = $this->_fenom->getCachedTemplate($tpl);
if ($cache instanceof Render) {
if ($cache->getTime() !== $time) {
return false;
}
}
// if not cached, check source's filemtime
if ($provider->getLastModified($tpl) !== $time) {
return false;
}
}
}
return true;
}