From e1a3f5f9bb0d580b1995e56aeb5a3ebf1f74ba78 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 4 Jun 2013 10:03:33 -0400 Subject: [PATCH] PreCache templates for performance. --- admin/home.php | 7 ++++++- admin/index.php | 21 +++++++++++++++++++-- includes/hoplite | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/admin/home.php b/admin/home.php index f0075b7..a36898c 100644 --- a/admin/home.php +++ b/admin/home.php @@ -26,8 +26,13 @@ use \hoplite\http; require_once HOPLITE_ROOT . '/http/action.php'; -class HomeAction extends http\Action +class HomeAction extends http\Action implements TemplatePreCaching { + public function TemplateSet() + { + return array('admin_index'); + } + public function Invoke(http\Request $request, http\Response $response) { $response->data['title'] = T('Home'); diff --git a/admin/index.php b/admin/index.php index fa14143..b760dbf 100644 --- a/admin/index.php +++ b/admin/index.php @@ -23,6 +23,7 @@ namespace bugdar\admin; use \bugdar; use \hoplite\http; +use \hoplite\views; chdir('../'); require_once './includes/init.php'; @@ -74,6 +75,22 @@ class FrontController { $this->controller->StopWithCode(http\ResponseCode::FORBIDDEN); } + + public function WillInvokeAction(http\Action $action, http\Request $request, http\Response $response) + { + $templates = array('admin_header', 'admin_footer'); + if ($action instanceof TemplatePreCaching) + $templates = array_merge($templates, $action->TemplateSet()); + views\TemplateLoader::GetInstance()->PreCache($templates); + } +} + +// Actions can implement this interface to have their required templates loaded +// with the common templates. +interface TemplatePreCaching +{ + // Return an array of template names to cache. + public function TemplateSet(); } $controller = new http\RootController($GLOBALS); @@ -94,9 +111,9 @@ $url_map->set_map(array( $output_filter = new http\OutputFilter($controller); $controller->set_output_filter($output_filter); -$tpl_loader = \hoplite\views\TemplateLoader::GetInstance(); +$tpl_loader = views\TemplateLoader::GetInstance(); $tpl_loader->set_template_path(BUGDAR_ROOT . '/admin/templates/%s.tpl'); -$tpl_loader->set_cache_backend(new \hoplite\views\PDOCacheBackend( +$tpl_loader->set_cache_backend(new views\PDOCacheBackend( Bugdar::$db, // PDO object. TABLE_PREFIX . 'template', // Database table. 'filename', // Name column. diff --git a/includes/hoplite b/includes/hoplite index d2f83c1..a7c5ff1 160000 --- a/includes/hoplite +++ b/includes/hoplite @@ -1 +1 @@ -Subproject commit d2f83c12edda9c38835a5a0561d781a6284baf91 +Subproject commit a7c5ff1323c5b72bedd54bd57c1279e780be7232 -- 2.22.5