I’ll admit it: drupal is amazing because you can build complex websites that are a snap to maintain and expand, especially for SEO purposes.  You can quickly publish content, slap on a forum or blog, build an efficient lead generation system…  In fact, just about all the sites we’ve been developing over the last 6 months are using the drupal framework.  I really could go on and on about the benefits of drupal, so go check it out.

But there’s a catch to using Drupal

Yes, drupal is actually very database intensive.  One page request results in around 100 queries to your database so drupal can quickly eat up your web server’s resources if you start getting hundreds or thousand of visitors – and that’s just for a simple website with a moderate number of modules installed (by the way you can trouble shoot database queries and bottlenecks using the devel module).

So what to do?  Enter the concept of "caching".  Caching means you calculate some peice of data once and then store is for quick retreival many times.  Drupal has a built in caching API for allowing you to write functions that take advantage of storing complex calculations pre-stored in a database table – so that means you don’t have to incur a ton of database hits every time your module or function runs.  Drupal 6 also has a built in page caching mechanism that caches all page requesets to your site, but is more of a global caching solution and wouldn’t really work for something like a social networking website or a site that needs to serve up constant, fresh content all the time (that’s where the API is useful, giving you granular caching control).

The Drupal Cache API

Drupal 6’s built in cache API is actually very simple, just

cache_set('my_key', $data_to_store)

to store some data in the default cache table.  You can name your key whatever you want so long as it doesn’t confilct with other keys.  Then use

cache_get('my_key')

to get your cached information, no need to serialized or unserialize objects as Drupal 6 does this for you. And then you can

cache_clear_all('my_key')

to force clear your cache.  You can also set an expire time on your cache_set function so that every so often your data will get refreshed with new information, see the drupal cache tutorials for specifics.

A working example of caching

So I really liked this beginners guide on drupal 5 caching but I am used to drupal 6 at this point.  So here is my example for drupal 6:

function my_module_function($reset=false) {
static $my_data;
if (!isset($my_data) || $reset) {
if (!$reset && ($cache = cache_get('my_key')) && !empty($cache->data)) {
$my_data = $cache->data;
} else {
// Create $my_data, do your calculations here, then...
cache_set('my_key', $my_data);
}
}
return $my_data;
}

The function is first looking if the reset flag is set or if the $my_data variable was previously created on the same page call, if not then we attempt to grab the data from cache.  If successful then we return the data, if not then we do our calculations from scratch and store the data into cache and return the data.

So what does drupal caching have to do with SEO?

If you’re looking to grow your website using drupal and put more pages (tickets) into the search engine index (lottery) then caching can help large websites from crashing once you do get traffic and keep your business from paying a lot of extra money for extra resources that you wouldn necessarily need.  Besides, you’re likely to have people and bots coming back to a site that loads faster vs a site that loads slow or doesn’t load at all (despite what Matt Cutts says since Google just wants data to throw on their shelves to increase advertising space).

So that’s it for now, happy caching and SEOing!

Comments

Your email will not be published. Required fields are marked *

Rich Yumul • 9 years ago

Nice tip on how to optimize a Drupal site!

Read More

Other posts you will enjoy...

RelationEdge Announces the Acquisition of Main Path Marketing and Launch of a Full-Service Marketing Cloud Practice
Twitter Moments – Should They Be a Part of Your Social Media Strategy?
Developing a Plan for Social Live Video
4 Common Email Problems and How to Solve Them