View RSS Feed

Nick's Hotaru CMS Blog

Experimental Caching

Rate this Entry
I turned on Hotaru's debug mode last night and was shocked to see that my offline test site with JapanSoc imported into it was firing over 400 database queries on the front page!

Hotaru's "Debug" mode isn't really for debugging yet, but it does show you the number of database queries, the page load time and memory usage. Those last two were respectable enough, but those 400 database queries just wouldn't do. As a result, I've come up with a "smartCache" function.

The smartCache function makes a single query to find the last time a specified database table was updated. If the table hasn't been updated for 10 minutes, it caches the results and loads them on every pageview until there's an update. When there is an update to the table, the cache is ignored and the results are pulled from the database.

The smartCache works in two ways. It can either cache database queries or HTML output, depending on the situation. On my test installation, I'm caching the database queries for the category bar, but the HTML output for the sidebar posts, comments and site activity.

I also made another big change to cut down on queries. Instead of pulling individual plugin settings and details from the database when needed, Hotaru does it all in one go at the beginning and then those settings can be retrieved from memory instead of the database. I'm currently looking at a memory usage of 7.4 MB for the front page, which seems to be average for a website.

So far, assuming no activity in the last ten minutes, database queries are down to 84 from 400 on the front page and as low as 36 for a story page with no comments.

I haven't committed these changes to the SVN yet, but will do soon.

Submit "Experimental Caching" to Digg Submit "Experimental Caching" to del.icio.us Submit "Experimental Caching" to StumbleUpon Submit "Experimental Caching" to Google

Comments

Trackbacks

Total Trackbacks 0
Trackback URL: