Brians Latest Comments Cached

After the success I had with Ultimate Tag Warrior I turned my eye to another popular WordPress plugin that I use: Brian’s Latest Comments.

This plugin lists the latest comments on your blog and I wanted to squeeze every bit of performance out of my server so I guessed that caching the output of the plugin would save several queries for every page generation. Comments are cached for an hour. The cache isn’t invalidated by a new comment so don’t worry if the comments list doesn’t update immediately after a comment is made.

Install

I used the same cache directory that WP Cache 2.0 uses, wp-content/cache/. You’ll have to create that directory and make sure the webserver can write to it. The simplest way of doing that is by running the command chmod 777 cache. Download the file below and copy it into your plugins directory. If you’ve never installed the original plugin you’ll need to download it and read the install.txt to find out how to use the plugin.

Download

brianslatestcomments.txt – rename to .php and copy into your plugins directory.

14 thoughts on “Brians Latest Comments Cached

  1. You didn’t mention which version of BLC you modified, so I’m going to assume it’s the latest and the same as what I’m using. Still it would be nice if you could mention the version number, and even better provide a diff so those of us who can be bothered can take a look at the exact changes before applying them.

    Thanks!

  2. Sorry, I should probably have looked into your modified source before asking about the version number. :/ My hands move faster than my brain, sometimes.

  3. can the refresh time intervals be tweaked? say, rather tan 1hr, change it up to 30mins or 1.5hrs…

    great work! There are a lot of big sites that can use this…

  4. Just a quick question:
    Why don’t you use WP-Cache if you want every last bit of performance?
    WP-Cache also caches Brian’s Latest Comments, no configuration needed…

    (But I do like invalidating the cache with every new commment – but there is a better way. Put BLC in a HTML file, and instead of dynamically adding it to the sidebar, include it via a php include so that you don’t have to have every page redone – just the BLC page)

  5. Why not just use WP Cache? You can use the latest comments plugin on any page but the comments will always be the same, given the same args to it.
    When someone visits a page that WP Cache hasn’t cached the cached comments will help.
    By default wp cache doesn’t cache every page either so the cached comments will reduce the load on those pages too.

    It should be easy enough to invalidate the cache. Add an action on the comment publish hook and simply remove cache/latest_comments*. I didn’t add that because it’s not important to me.

    You can change the time to live of the cache by searching the plugin for “3600” and change it to the number of seconds you want the cache to live for.

  6. Hey there. Unfortunately, it still crashes the server. everything is fine until the hour mark hits & the recent comments is updated. Load shoots to around 100 & boom.

    I have 2gigs on the server, with plenty of hd space. Do you think it is b/c the plugin in caching a lot of information or what?

  7. Moe – are you using WP Cache? If you were, WP Cache would prevent all your page requests at that one instant trying to regenerate the latest comments cache. The latest comments cache might regenerate when someone visited an obscure page then.

    There might be some problems with your config, or your comments and posts tables are *huge*. With 2GB of RAM that shouldn’t be a problem though.

    You could also cron a job on your server to recreate the cache file every hour or so. Check for a value in $_GET and if it’s there then create the cache. Remove the time check in the code of course!

  8. Great plugin—the lag Brian’s Latest Comments was causing in loading my sidebar was driving absolute crazy.

    However, I do have a question—how do you make it so that when you click on the commenter name, it goes to the comment rather than the commenter’s website?

  9. Robert – open up the plugin and search for the word “url” in the code. There’s an if() condition there to check if a url has been entered in the form.

    Just comment out the “if() {} else” and the final “}” to leave the link to the comment!

Leave a Reply

%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close