Assume I have a menu that’s simply static, for most sites, or rather, let’s use my example, a blogging site, it almost never, never changes.

Why not hook it to a transient that never expires unless changed? So, if you play with that menu, you’d reset the transient and get the newer instance, but otherwise, it’ll never be retrieved with the full query itself.

Same for comments, same for, well, almost everything.

Is this a bad idea?

I understand this is more philosophy-architecture oriented but I think it’s an important question with deep implications.

2 s
2

Actually, doing it for menu is good, you can even store entire HTML output and cut not only queries, but processing time too. Additionally, you can use WP_Object_Cache directly in conjunction with Redis/Memcached backend and avoid even single DB query for the transient itself.

Re comments – they do change, so running WP_Comment_Query is unavoidable. However, you can cache them as well, for some short amount of time. Say, 5 minutes. In this case, you need to find the balance between how much speed boost you gain and the delay before users will see their newly made comments.

Rule of thumb is, cache when needed, when it gives you positive impact and does not introduce negative impact.

WordPress already does great job in caching most important things (including menu items) – just put the object cache class in WP-content and add object cache backend on your server.

Leave a Reply

Your email address will not be published. Required fields are marked *