• 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.

Viewing 1 replies (of 1 total)
  • Thread Starter alanft2

    (@alanft2)

    never mind – i think wp-cache-2 is what i’m after. i thought it was out of date

Viewing 1 replies (of 1 total)
  • The topic ‘Caching the main query for the front page’ is closed to new replies.