Memcached is an open source caching system with high performance which will increase your site's performance by reducing database load. It is used to speed up dynamic database-driven websites by caching data. In this article we will study about how we can integrate Memcached to our drupal system. Although Drupal saves cached information into database tables but it still requires server to hit the database to retrieve the cached data. So in this case Memcached speeds things up by saving this information in RAM memory, which is much faster to use.
Now Lets setup Memcache server by installing Memcached packages. Run the following command lines to install the Memcached packages.
$ sudo apt-get install memcached libmemcached-tools $ sudo apt-get install php5-dev php-pear make $ sudo pecl install memcache
$ sudo vim /etc/php5/conf.d/memcache.ini
Made sure the below lines are present in this file.
The default memory value is 16MB, but the more memory given to Memcached the better. Try allocating as much as 1/4 of your total available RAM. To make these changes open up memcached.conf:
$ sudo vim /etc/memcached.conf
Add the below code to the memcached.conf file.
# Change this default value to ~ 1/4 of your total # available RAM -m 16
Restart Memcached and Apache for these change to go into effect:
$ sudo /etc/init.d/memcached restart $ sudo /etc/init.d/apache2 restart
Now lets check whether the Memcached is running. To do so, run below command:
$ sudo netstat -tap | grep memcached
If you see something like below, then memcahed server is successfully configured:
tcp 0 0 localhost:11211 *:* LISTEN 25266/memcached
So now lets intergate Memcache for Drupal 7. To do so, you need to download and Enable contributed module Memcache API and Integration. Then add the following to settings.php:
$conf['cache_backends'] = 'sites/all/modules/contrib/memcache/memcache.inc'; $conf['cache_default_class'] = 'MemCacheDrupal'; $conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
Thats it. You have successfully configured memcached for your drupal system. Hope this short article has been helpful. Use the comment box below to share your views and doubts about this article here