Increase Speed with Block Caching

 Sunday, November 11th, 2007
Mods Compatibility
IndexU 5.4.X
IndexU Deluxe

When browsing our site, you'll noticed that we have a lot of stuff in our left and right panel. There are category list, directory stats, pagerank stats, blogs component (category, recent post, archive), etc. All of them are IndexU component, or usually refer as "blocks". Most blocks usually need database query, so when using a large number of blocks it might slowdown your site since more database query need to be performed.

So here we use a caching mechanism for blocks in order to reduce the query and increase the site speed.
Here is the code for caching our left blocks by editing the header.html template :

Content visible to member only. Please register or login first.

The code above will cache 4 blocks and stored them in a cached file named "block.left.html" under cache folder. You can view the cached content here : http://www.indexudirectory.com/cache/block.left.html
So the first request will build the blocks using database as usual, but the next request will simply load the static cached file so no database query will be performed and the page will load faster. The 4 blocks above will be cached for 86400 second (1 day).

We use the similar code above to cache our right blocks by editing the footer.html template and stored the cached content in "block.right.html" file.

This mods is very useful for us since we use "blocks" extensively :)
We hope this simple tips will be useful for you too.

Leave a Reply