Remove two-tier caching of template files

This commit is contained in:
Kijin Sung 2016-02-11 10:44:47 +09:00
parent d5a5364814
commit 25eef85d8a

View file

@ -117,8 +117,6 @@ class TemplateHandler
*/
public function compile($tpl_path, $tpl_filename, $tpl_file = '')
{
$buff = false;
// store the starting time for debug information
if(__DEBUG__ == 3)
{
@ -143,37 +141,13 @@ class TemplateHandler
$source_template_mtime = filemtime($this->file);
$latest_mtime = $source_template_mtime > $this->handler_mtime ? $source_template_mtime : $this->handler_mtime;
// cache control
$oCacheHandler = CacheHandler::getInstance('template');
// get cached buff
if($oCacheHandler->isSupport())
// get cached file
if(!file_exists($this->compiled_file) || filemtime($this->compiled_file) < $latest_mtime)
{
$cache_key = 'template:' . $this->file;
$buff = $oCacheHandler->get($cache_key, $latest_mtime);
}
else
{
if(is_readable($this->compiled_file) && filemtime($this->compiled_file) > $latest_mtime && filesize($this->compiled_file))
{
$buff = 'file://' . $this->compiled_file;
}
FileHandler::writeFile($this->compiled_file, $this->parse());
}
if($buff === FALSE)
{
$buff = $this->parse();
if($oCacheHandler->isSupport())
{
$oCacheHandler->put($cache_key, $buff);
}
else
{
FileHandler::writeFile($this->compiled_file, $buff);
}
}
$output = $this->_fetch($buff);
$output = $this->_fetch($this->compiled_file);
if($__templatehandler_root_tpl == $this->file)
{
@ -358,54 +332,20 @@ class TemplateHandler
* @param string $buff if buff is not null, eval it instead of including compiled template file
* @return string
*/
private function _fetch($buff)
private function _fetch($filename)
{
if(!$buff)
{
return;
}
$__Context = Context::getInstance();
$__Context->tpl_path = $this->path;
$level = ob_get_level();
$__ob_level_before_fetch = ob_get_level();
ob_start();
if(substr($buff, 0, 7) == 'file://')
{
if(__DEBUG__)
{
//load cache file from disk
$eval_str = FileHandler::readFile(substr($buff, 7));
$eval_str_buffed = "?>" . $eval_str;
@eval($eval_str_buffed);
$error_info = error_get_last();
//parse error
if ($error_info['type'] == 4)
{
throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}");
}
}
else
{
include(substr($buff, 7));
}
}
else
{
$eval_str = "?>" . $buff;
@eval($eval_str);
$error_info = error_get_last();
//parse error
if ($error_info['type'] == 4)
{
throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}");
}
}
include $filename;
$contents = '';
while (ob_get_level() - $level > 0) {
$contents .= ob_get_contents();
ob_end_clean();
while (ob_get_level() > $__ob_level_before_fetch)
{
$contents .= ob_get_clean();
}
return $contents;
}