• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Cache templates to avoid 1 additional query for each callback

Marcus

Well-known member
#1
In Debug I see one additional query per each callback function returning a template:
PHP:
<xen:callback class="My_Callback_ForumList" method="getForumList" params="{$visitor}" />
PHP:
class My_Callback_ForumList {
  public static function getForumList($content, $params, \XenForo_Template_Abstract $template) {
       return $template->create('custom_template', $templateParams);
   }
}
How can I cache them all? With template caching? http://xenforo.com/community/threads/how-to-use-template-hooks.13167/ I thought xenForo caches most stuff on its own today :D
 

digitalpoint

Well-known member
#3
Side note, but you would be SO much better off storing templates as files so your opcode cache can pre-compile the templates. As a bonus, it doesn't need *any* queries to get templates.
 

Marcus

Well-known member
#4
Side note, but you would be SO much better off storing templates as files so your opcode cache can pre-compile the templates. As a bonus, it doesn't need *any* queries to get templates.
Forgot to activate this option again. Thanks ! The more you know the system, the easier it is to find the right solution :)
 

Luke F

Well-known member
#5
In your template_create event listener, for $templateName PAGE_CONTAINER (or something more specific if possible), call $template->preloadTemplate('your_template')
 

Marcus

Well-known member
#6
Thanks. Now I wonder if the addon on my "fetch templates as files" enabled forum would me minimal faster with or without adding the cache routine.