MyBB Community Forums

Full Version: Template Cache
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Not a plugin, but a set of small patches that caches templates to disk. Requires PluginLibrary 12 for the cache functions. And the Patches plugin to actually apply the patch.

The cache saves one database query per request plus additional queries in case you have plugins that don't put their templates into $templatelist for some reason. (The cache makes $templatelist entirely superfluous).

Does it make your site load faster? Not really. It may in fact make it slower, since instead of a simple DB query, it has to load PluginLibrary and the cache file. Which is slower than a DB query unless PHP itself is cached/accelerated/optimized properly. Your database would have to suck or be located on a different server for it to make any difference.

What's the point then? None really, except it could be done.

I considered making this a plugin, with additional features such as an advanced template editor that allows you to edit templates inline (on the site they appear on) and helps you create entire template sets from scratch, but I don't have the time for it...
Nice idea, but as you said it seems a tad pointless. I believe that phpBB store their templates in a similar way (on the disk).
Yes, yes, ...

Although it does lead to interesting discoveries, for example did you know that editing xmlhttp_* templates in your theme is utterly pointless, as they won't ever be used by xmlhttp.php anyway? xmlhttp.php doesn't load themes, so when loading templates with no known theme or template set, it ends up loading the master templates instead.

You can work around this by creating a global template, for example for xmlhttp_inline_post_editor; except MyBB doesn't let you create a global template with that name directly ("The template title is already in use. Please use a different title.") so you have to create it using a different name, then edit it to change the name to xmlhttp_inline_post_editor (which works fine).

Global templates override master templates, for all template sets, so that works.

MyBB should allow creation of global templates with existing names; it's a feature, as it allows using the same edit across all template sets.
I never knew that, no. It's an interesting tidbit for certain though. I can see why themes aren't loaded in xmlhttp (unnecessary bloat isn't needed), but I can also see the other side of the issue where users want different template responses for requests depending on theme.
That is why I had to build my own xmlhttp script for ASB-- I have to be able to have theme info to produce the side box content-- of course, you can always load init.php and the session and then load your own theme info from the info in $mybb->user['style'] . . .
I did something like this when I was on free hosting which had a 10MB MySQL size limit.
Having multiple themes installed meant that the templates table took a fair portion of that 10MB.

I did find that on disk templates were often slower (it seems MySQL is more efficient at pulling this than the filesystem), but then again, I haven't extensively tested it and don't know if, say, SSDs narrow the margin.
Does this patch worth using nowadays if you have uncached templates?