This document discusses how to use Memcache to reduce database load in Drupal. It begins by explaining what Memcache is - an in-memory key-value data store that stores data in RAM for faster access. It then covers why Memcache is needed to improve performance, how to install Memcache and the Memcache module for Drupal, and how to configure settings.php to use Memcache as the default cache storage in Drupal. The document concludes with some merits and demerits of using Memcache.
Powerful Google developer tools for immediate impact! (2023-24 C)
How to reduce database load using Memcache
1. How to reduce database load using
Memcache
A Ajay Kumar Reddy
https://www.drupal.org/u/ajay_reddy
2. ● What is Memcache?
● Why do we need Memcache?
● How to install Memcache?
● How to configure Memcache in Drupal?
● Merits and demerits of Memcache.
Agendas
3. ● Memcache is an in-memory Key-Value pairs data store.
● The Memcached server itself stores all the actual data in
area of allocated RAM on the server (configurable).
What is Memcache?
4. ● Well, having a storage frequently in RAM uses less time
to fetch DATA.
● Can split upon Multiple applications based on
“PREFIX”.
Why do we need Memcache?
5. ● Open the terminal on your local machine and run the following codes:
○ sudo apt-get update
○ sudo apt install memcached
○ sudo apt install php-memcached
● Make sure Memcache daemon is working fine by running the following
command:
○ “ps aux | grep memcached”
● Also, check whether the Memcached extension is properly configured
in PHP7 by creating info.php page.
How to install Memcache?
6. How to install Memcache?
● sudo nano /var/www/html/memcache/info.php
● And enter the below code
● <?php
phpinfo();
?>
● Now restart both Memcached and php7-fpm services
● service memcached restart
● service php7.0-fpm restart
● Go to any web browser and access info.php as
“http://localhost/memcache/info.php”.
7. ● Download and Install Memcache and Memcache Storage
modules from drupal.org
○ drush en memcache memcache_storage -y
● Here we are using Memcache storage module to integrate
Drupal and Memcached.
● Memcache Storage module used to store data in Memcache
and also to show statistics.
How to configure Memcache in
Drupal?
8. Configure settings.php
● // Set’s default cache storage as Memcache and excludes
database connection for cache
$settings['cache']['default'] =
'cache.backend.memcache_storage';
● // Set’s Memcache key prefix for your site and useful in
working sites with same memcache as backend.
$settings['memcache_storage']['key_prefix'] = '';
● // Set’s Memcache storage server’s.
$settings['memcache_storage']['memcached_servers'] =
['127.0.0.1:11211' => 'default'];
10. ● It is open source.
● Perfectly efficient for
websites with huge
database load/page
hits.
● An client server
application over TCP
and/or UDP.
Merits and Demerits of Memcache
● Loss of data is system
reboots.
● RAM usage.
● Removes least data
first.
● Shares data all over
server if not configured
with application key.