Caching the main query for the front page
-
When I checked the queries on our blog using print_r($wpdb->queries) I discovered that the main query for the front page’s 10 threads was by far the biggest drain of time – taking as much as 2 seconds on occasion. So I ploughed through the code to see if there was a way to use wp_cache.
In the end I couldn’t find any hook or anything to exploit, so I HACKED into the &get_posts function (which in 2.1 moved to the includes/query.php)
if (($this->is_home == true) && [more unimportant logic here])
{ $this->posts = wp_cache_get('front_page', 'ft_cache');
if ($this->posts ===false)
{ $this->posts = $wpdb->get_results($this->request);
wp_cache_set('front_page', $this->posts, 'ft_cache', 3600); }
}now this does what I want (along with a wp_cache_delete hooked into publish_post). BUT is there any better way of doing this? it just seems like something that would already be solved.
- The topic ‘Caching the main query for the front page’ is closed to new replies.