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. 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. 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. Types of caching
● File based caching
● Database based caching (Drupal default)
● Memory based caching (Memcache)
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. 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. 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. A web hit without cache
USER 1
USER 2
USER 3
USER 4
USER 5
INTERNET
APACHE
MYSQL
DB
INDEX.PHP
10. A web hit with cache
USER 1
USER 2
USER 3
USER 4
USER 5
INTERNET
APACHE
MYSQL
DB
INDEX.PHP
MEMCACHE
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. 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