Memcache and Drupal - Vaibhav Jain

1,123 views
1,014 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,123
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Memcache and Drupal - Vaibhav Jain

  1. 1. Memcache and Drupal
  2. 2. 1. Introduction to caching / memcache 2. Installing memcache on system 3. Integrating memcache in Drupal (Made quite easy with drupal). 4. Memcache multiple instances 5. Multiple servers for effective performance in case of high traffic sites. 6. Use of Drupal caching in code to set, get and purge data as per requirements.
  3. 3. What is Caching ● Wikipedia - “ A web cache is a mechanism for the temporary storage (caching) of web documents, such as HTML pages and images, to reduce bandwidth usage, server load, and perceived lag “ ● Process of storing data for faster access ● Place where this data is stored is referred to as Cache
  4. 4. Why do we need Caching ● Reduce number of “select” queries to DB ● Reduce number of hits made to 3rd party services / API’s ● Reduce time where heavy computation is required. ● Reduce the file system access
  5. 5. Types of caching ● File based caching ● Database based caching (Drupal default) ● Memory based caching (Memcache)
  6. 6. What is Memcache ● Wikipedia- Memcache is a general-purpose distributed memory caching system. ● It is used to speed up dynamic databasedriven websites by caching data in RAM to reduce the number of times an external data source like a database or API is read.
  7. 7. Anatomy and Terminologies ● Stores data in Key Value pair ● Main operations ○ Add data - set ○ Fetch data - get ○ Remove data - delete ● Cold Cache / Warm Cache ● Cache Hit / Cache Miss
  8. 8. Anatomy and Terminologies ● No Persistence data storage ● No Redundancy ● No failover handling ● No authentication required ● A Key cannot store more than 1 MB data ● Key length is limited to 250 characters
  9. 9. A web hit without cache USER 1 USER 2 USER 3 USER 4 USER 5 INTERNET APACHE MYSQL DB INDEX.PHP
  10. 10. A web hit with cache USER 1 USER 2 USER 3 USER 4 USER 5 INTERNET APACHE MYSQL DB INDEX.PHP MEMCACHE
  11. 11. Installing Memcache Simple set of commands ● Install Memcached on your server ○ apt-get install memcached libmemcached-tools ● Install memcache PHP extension using PECL ○ apt-get install php-pear ○ pecl install memcache ● Add memcache.so to php.ini ○ vim /etc/php5/conf.d/memcache.ini ○ extension=memcache.so
  12. 12. Integrating Memcache in Drupal ● Already has module for integrating memcache - https: //drupal.org/project/memcache ● Simple Integration ○ No adding classes ○ No need to call and use methods ○ No need to take care of bins name, if you are using multiple ○ Memcache Admin included ○ Test provided to check your memcache setup ○ Works with both, Memcache and Memcached
  13. 13. Integrating Memcache in Drupal Add below lines to settings.php 1. $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc'; 2. $conf['cache_default_class'] = 'MemCacheDrupal'; 3. $conf['cache_class_cache_form'] = 'DrupalDatabaseCache'; - Optional
  14. 14. Memcache Multiple Instances 256 MB 64 MB 64 MB 64 MB 64 MB
  15. 15. Memcache Multiple Instances Command - /usr/bin/memcached -u root -p 11212 -m 64 -d
  16. 16. Memcache Multiple Servers
  17. 17. Cache Examples cache_set cache_get cache_clear_all Live Example(s)

×