WordPress.org

Ready to get started?Download WordPress

Forums

using cache on the homepage 10 records (and a minor SAVEDQUERIES query) (5 posts)

  1. alanft2
    Member
    Posted 8 years ago #

    (i'm on 2.0.4)

    when i got savedqueries working and got to see where all the time is being spent on my homepage, the determining step was selecting the recent 10 posts. it varied from .2s to close on 2s at some points. everything else rarely added .3s more.

    Now perhaps I could look into just why that query is taking so long, but having just learned how to use the WP cache I thought I'd try using it instead. what i ended up doing was hacking get_posts in classes.php with something like

    if ($this->is_home) { try_using_special_cache_code } else {$this->posts = $wpdb->get_results($this->request);}

    and using an add_action('publish_post'... to clear the cache when a new post is written.

    Now it works a treat - the front page rarely loads any slower than 0.3s - but this seemed like such an obvious thing to want to do, and yet the WRONG way of doing it, I wondered if anyone could point me to a plugin/filter/hook that would get this done neater.

    minor savedqueries query:

    I added define('SAVEQUERIES', true); to wordpres/index.php before require('./wp-blog-header.php') and it just doesn't seem to have any effect. This must be PHP weirdness because a multi-file search shows it is only used in wp-dp.php which only defines it false if undefined.

    hacking the top bit of wp-db.php so it defines it as true means that the if (SAVEQUERIES) lines later on do happen and gives me the info i was after (above)

  2. yosemite
    Member
    Posted 8 years ago #

    Take a look at wp-cache...

  3. alanft2
    Member
    Posted 8 years ago #

    Ah, thank you.

    (I am never sure if the stuff out there is out of date. Most things that say "cache" seem to be out-dated by 2.0.)

  4. yosemite
    Member
    Posted 8 years ago #

    The only issue I came across with that version (which may or may not effect you, just putting it here FYI):

    If you have "blank pages" in WordPress with wp-cache turned on after you upgrage to PHP 5.1.2 - there is simple fix to solve the problem:-

    1. Open wp-cache-phase2.php file* in your favourite text editor
    2. Find out wp_cache_ob_end function
    3. then inside that function find out line with: ob_end_clean(); (it should be line 219 or about)
    4. and finally replace that line with: ob_end_flush();

  5. davidchait
    Member
    Posted 8 years ago #

    the internal WP 'object cache' should only be used by knowledgeable admins, on systems tuned for caching, with a replacement for the default caching mechanism (to use memcached or the like).

    for most people, especially on shared hosting, WP-Cache 2, a plugin (not the internal feature..), does a good job of caching the results of the page generation in its entirety, and presenting the results rather than regenerating every request.

    -d

Topic Closed

This topic has been closed to new replies.

About this Topic