Database-driven websites and caching

posted on 14 December 2007 | posted in Performance

Database-driven websites and caching Database-driven websites render their web pages via web scripts (e.g. PHP, ASP) that in turn get content from a database (e.g. mySQL). These types of websites are commonly e-commerce, blog / content-managed websites - or shall we say, the vast majority of websites out there now.

These make life easy for the website owner who can easily update their website easily and quickly. However, for web hosts, these pose a threat to the stability of their server. Poorly scripted websites can cripple a server with too many database calls, or nested loops of logic rendering web pages.

It's important to be aware of the code running on each of your websites on your server. This might sound like an impossibility if you have dozens of websites - but actually these days, it is easier with the majority of websites running under template applications - e.g. WordPress, OSCommerce, Zen Cart, Drupal etc. It's important to find out which templates support the caching of content, which greatly reduces the overheads to your server's CPU.

What is caching?

A typical website has areas of every web-page that are the same. The navigation areas of a website are typically (or should be!) the same on every page. An e-commerce site might have a list of product categories down the left-hand side of each page. If this list of categories is NOT cached, every single time a page loads, the web scripts need to access the database in order to populate this list. If the list of categories IS cached, there's no need to call the database - you can simply get this list from a previously generated file - making life a LOT easier for your server. This file is only ever updated when there's a change in the list of product categories.

WordPress and caching - a good example

WordPress have a caching plug-in for their blog software called wp-cache. However, many WordPress blogs do not have this installed so their websites suffer from the inefficiency of having their pages completely rendered via database calls every time there's a page load. The result? When someone receives a spike in traffic, like from a link via social website like, their website inevitably crashes because their server just can't handle the amount of requests to its database. WordPress is infamous for crashing servers if a website is using WordPress without caching. A cached website would be FAR less demanding on the server.

Confessions of a web developer

A long time ago, before we became web hosts ourselves and could actually see how our website code affects the resources of the server, we were blissfully ignorant of the connection between website code and the server. We just assumed servers somehow would handle whatever we threw at them. We assume there are a lot of web developers out there who don't realise what their code is doing to servers so please be aware of any bespoke applications you host!


We strongly advise you run web applications that use caching as described above, in order to maximise the amount of traffic your server can receive.

recommend a friendRecommend this blog entry to a friend