I’m rewriting a template for a wordpress based site which has some issues with load speed and I’m looking for the best way to speed things up on the code side first.
Since the site uses many “boxes” (like headlines, most views, recent comments, post of the week, and so on) which are reused in many different pages, I thought about a system to reduce the number of queries made by caching these sections one by one.
It would work like this:
- the code for every box will be a function in
functions.php
functions.php
will include another file with an array (say$created
) which records the last time a box was created- every function will first check
$created['someBox']
: if less than X time has passed loadrendered_someBox.html
and return it, else do full db processing, saverendered_someBox.html
, return it and update time in$created
- template files will just call these functions when needed
Is this a sensible approach in reducing load or does it add more overhead than it takes? How can this be improved?
I would recommend using WordPress’ native
WP_Object_Cache
class and functions:http://codex.wordpress.org/Class_Reference/WP_Object_Cache
And you could have a 2-level cache: cached HTML for presentation (for every “box”), and cached DB results (as some boxes could be different presentations of the same data).