Hi, I was wondering if anyone could shed any light on this question about caching weblog tags.
I’m using
{exp:weblog:entries weblog="news" require_entry="yes"}
to pull out a single entry.
I am debating over methods of getting the page title into the title tag in my header embed…
Using same weblog tag twice
{embed="embeds/.htmlheader" title="{exp:weblog:entries weblog="news" require_entry="yes"}{title}{/exp:weblog:entries}"}
{exp:weblog:entries weblog="news" require_entry="yes"}
<h1>{title}
{body}
{/exp:weblog:entries}
or
Using reeposition plugin
{exp:reeposition}
{embed="embeds/.htmlheader" title="{reeposition:put_item}"}
{exp:weblog:entries weblog="news" require_entry="yes"}
<h1>{reeposition:item}{title}{/reeposition:item}</h1>
{body}
{/exp:weblog:entries}
{/exp:reeposition}
I think I read somewhere that the results of the weblog tag are cached, so does this mean I can keep on reusing the same tag in a template and not hit the database any more?
Can I reuse the tag across several embeds and still have the benefit - ie is the cache per embed or per whole page request?
Am I better off using the reeposition plugin?
Your thoughts would be appreciated, please experts!
You may not find this helpful, but one of the best ways to test this sort of thing is to turn on template debugging; whip up a couple templates, one using each technique; repeatedly run each template; and compare the debugging info for each.
Generally speaking, EE’s DB caching mechanism allows it to not have to run the same queries over and over. (Note that not all queries are cachable.) So it’s true that subsequent runs of the exp:weblog:entries tag will require fewer DB hits than the first. But that’s not the only thing going on when you load exp:weblog:entries (or any tag) multiple times. You also need to think about the overhead associated with calling such a large and complex function over and over again.
Reeposition is little more than a cut and paste mechanism, so generally speaking it’s going to be pretty speedy relative to to the Weblog module’s entries() function. Speed might not be the only thing you’re interested in, though. You might value code maintainability, for example. I’ve seen some pretty convoluted uses of Reeposition, and while they work just fine, a developer unfamiliar with the plugin might not have any idea how to maintain the template code.
Is that any help?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.