开发者

Custom section-based cache for wordpress site

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 开发者_JS百科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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜