PreCache templates for performance.
authorRobert Sesek <rsesek@bluestatic.org>
Tue, 4 Jun 2013 14:03:33 +0000 (10:03 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Tue, 4 Jun 2013 14:03:33 +0000 (10:03 -0400)
admin/home.php
admin/index.php
includes/hoplite

index f0075b7471a1eb8b962f433e76ec6681c61fb02d..a36898c47df6768a2230dd56209a071ee87bb2ea 100644 (file)
@@ -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');
index fa1414381d04391fa6a91926d8764eb60db47e9b..b760dbfa3a894b6190d3d4fe4ed35a2b235f4f97 100644 (file)
@@ -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.
index d2f83c12edda9c38835a5a0561d781a6284baf91..a7c5ff1323c5b72bedd54bd57c1279e780be7232 160000 (submodule)
@@ -1 +1 @@
-Subproject commit d2f83c12edda9c38835a5a0561d781a6284baf91
+Subproject commit a7c5ff1323c5b72bedd54bd57c1279e780be7232