views:

30

answers:

1

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 load rendered_someBox.html and return it, else do full db processing, save rendered_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?

+2  A: 

You might want to look at Wordpress's transients API (if you're using 2.8 or later), which uses the database for storage.

It's quite possible that caching data to the file system wouldn't improve performance. The Wordpress object cache originally worked in this way and was changed for this reason.

Richard M
Thanks that seems interesting. My main concern now is taking some load off mysql, that's why I thought of sharing it with the filesystem. If using the database for caching will still reduce the overall load, that's fine too.
kemp
The best thing to do to reduce load on the database would be to set up a full page cache system (using a plugin like WP Super Cache), or to use the Wordpress object cache with a back-end like Memcached (although this is obviously a bit more difficult to set up).
Richard M