Performance boost

Cache the widget and refresh it when any content edited or new content
added.
This commit is contained in:
Danang Probo Sayekti 2015-08-17 11:43:29 +07:00
commit ffb46f9981
3 changed files with 128 additions and 41 deletions

View file

@ -311,7 +311,7 @@ function render($view, $locals = null, $layout = null)
$dir = 'cache/page';
$cachefile = $dir . '/' . $c . '.cache';
if (is_dir($dir) === false) {
mkdir($dir, 0777, true);
mkdir($dir, 0775, true);
}
}
@ -336,12 +336,22 @@ function render($view, $locals = null, $layout = null)
$layout = "{$view_root}/{$layout}.html.php";
header('Content-type: text/html; charset=utf-8');
ob_start();
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
require $layout;
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
echo "\n" . '<!-- Dynamic page generated in '.$total_time.' seconds. -->';
if (!$login) {
if (!file_exists($cachefile)) {
echo "\n" . '<!-- Cached page generated on '.date('Y-m-d H:i:s').' -->';
file_put_contents($cachefile, ob_get_contents());
}
}