Increase Drupal Performance by using Memcache

When site starting to get bigger with thousands of users and millions of records in database and lots of traffic performance becomes a major issue. Drupal is very powerful tool but it requires some fine tuning. I have built sites with thousands of users and hundreds of modules. What is Mencache? Memcached is an in memory key value store in a form of very small chunks of arbitrary data i.e (strings, objects) from results of database calls, API calls, or page rendering. It is might look simple but it enormously powerful.

Adding memcache to a Drupal site will massively increase the performance (x2 is not unusual).

Following is a basic configuration (add this to the settings.php configuration)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* Memcache configuration.
*/
define(‘MEMCACHE_PATH’, ‘sites/all/modules/contrib/memcache/memcache.inc’);

// Include the base cache, because memcache extends the class provided in the base cache.
include_once(‘./includes/cache.inc’);
// Include the memcache files.
include_once(MEMCACHE_PATH);

// Optionally configure a prefix; most sites won’t need this.
# $conf[‘memcache_key_prefix’] = ‘foo’;

// Declare memcache as a potential backend.
$conf[‘cache_backends’][] = MEMCACHE_PATH;

// Set the default cache to use memcache.
$conf[‘cache_default_class’] = ‘MemCacheDrupal’;

// Form-cache must use non-volatile storage.
$conf[‘cache_class_cache_form’] = ‘DrupalDatabaseCache’;
There is a very brilliant mmemcache API module on drupal.org

Leave a Reply

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