01 Oct 2014 Memcached with WordPress
Memcached is a free open-source caching system, used to speed up the dynamic web content. It can be used with several technologies including WordPress.
“Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.“ – memcached.org
We will install the memcached server on Ubuntu 12.0 machine.
$sudo apt-get install memcached
make sure that the memcached is started.
$sudo /etc/init.d/memcached status * memcached is running
Edit the configuration file of the memcached.
$sudo vim /etc/memcached.conf -d #logfile logfile /var/log/memcached.log #to enable verbose -vv #memory max size -m 64 #port number -p 11211 #user running the memcached -u memcache #memcached server listen to the private ip -l 10.0.0.100
make sure to restart the server after editing the configuration file
$sudo /etc/init.d/memcached restart
Note that memcached module in nginx is only able to retrieve data from the cache, it doesn’t store the web pages in the cache, the storing process is done by your application so you must install a plugin on wordpress to do the caching.
The plugin will instruct php to cache the accessed web pages in the memcached, we chosed wp-ffpc plugin which is powerful and very easy to configure.
After installing the plugin, make sure to configure it so that memcached key would be $scheme://$host$request_uri which will match the key on the webserver configuration and the ip would be ip of the memcached server and you good to go.
To make sure that memcached works and storing data, go ahead and access the website and then telnet to the memcached server with port 11211 (default port) and type stats.
$sudo telnet 10.0.0.100 11211 Trying 10.0.0.100... Connected to 10.0.0.100. Escape character is '^]'. stats
STAT cmd_get 0 STAT cmd_set 3 STAT cmd_flush 0 STAT cmd_touch 0 STAT get_hits 0 STAT get_misses 0
This means that memcached issued 3 set commands so the storing process with memcached works.