Memcache is an in-memory (RAM). It store data in Key-Value Format. Memcached server automatically stores all the content (data) in allocated RAM on the server.
After configure memcache, it increase Drupal Site performance by moving standard caches out of the database.
Drupal does not come with memcache by default if we want to install it then we have to install it on server.
There are many steps that how to install memcache on the server and how to configure it with drupal 8 for reducing the load on the database with every page request.
Step1 :- Open terminal of your machine and run following commands :-
a. sudo apt-get update
b. sudo apt install memcached
c. sudo apt install php-memcached
Step2 :- Check that Memcache daemon is working by using the following command :
a. "ps aus | grep memcached"
Step3 :- Also, check Memcache extension is configured in PHP. For that you have create a file phpinfo.php then write below code.
<?php
phpinfo();
?>
or
sudo vi /var/www/html/memcache/phpinfo.php
And write below code
<?php
phpinfo();
?>
Step4 :- Now restart the memcache and apache2
a. service memcached restart
b. service apache2 restart
Step5 :- Open any web browser and hit phpinfo.php like
http://localhost/memcache/phpinfo.php
then serach memcache
Step 6 :- After installing memcache on server, download two module for drupal 8 site and enable its.
a. memcache
b. memcache storage
Step7 :- Now, Open your drupal site setting.php file and write below code.
Here, we are using memcache storage for drupal 8.
// 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'];
To debug Memcache include below code following above code in settings.php
// Enables to display total hits and misses
$settings['memcache_storage']['debug'] = TRUE;
Note :- Get saved memcached value from memcached server terminal using memached key
Now you know how to configure Memcache with Drupal 8.
Go to your drupal website and try it. If you face in problem in installing and configure memcache with drupal 8, do post a comment below.


Comments
Post a Comment