1. 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

Discussion in 'XenForo Development Discussions' started by Marcus, Aug 27, 2013.

  1. Marcus

    Marcus Well-Known Member

    In Debug I see one additional query per each callback function returning a template:
    <xen:callback class="My_Callback_ForumList" method="getForumList" params="{$visitor}/>
    class My_Callback_ForumList {
      public static function 
    getForumList($content$params, \XenForo_Template_Abstract $template) {
    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
  2. Chris D

    Chris D XenForo Developer Staff Member

    Yeah you need to look at the template_create event listener.
    Marcus likes this.
  3. digitalpoint

    digitalpoint Well-Known Member

    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.
  4. Marcus

    Marcus Well-Known Member

    Forgot to activate this option again. Thanks ! The more you know the system, the easier it is to find the right solution :)
  5. Luke F

    Luke F Well-Known Member

    In your template_create event listener, for $templateName PAGE_CONTAINER (or something more specific if possible), call $template->preloadTemplate('your_template')
  6. Marcus

    Marcus Well-Known Member

    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.

Share This Page