Magento Part 6 - Caching

<< Back to Magento Performance Tips for Scalability Homepage
With Magento you need to utilise some sort of caching service for it's performance to be acceptable.


Memcache is a really easy caching service to setup. Simply setup memcache on all of your front-end servers.

Add this config to your local.xml (I just use it for staging and production environments).


Redis Cache

Redis is an amazing caching platform that you can use with Magento. The great news is you can easily setup Redis on AWS ElasticCache.

Below is an example of a Redis configuration in local.xml



This is where the fun begins! Varnish is a front-end proxy (or reverse proxy). Varnish is amazing, however with Magento it can be a pain to configure correctly (give yourself a few days to get this configured correctly). The setup is easy, it is the testing and tuning that takes some time. I use a free Magento extension called 'Turpentine - varnish cache' to connect Magento and Varnish.

Grab yourself a copy here

This is the basic setup

  1. Install the Varnish Turpentine extension for Magento.
  2. Install Varnish on all your front-end servers (You could run this one separate servers if you wish, but I haven't needed to).
  3. Change apache over to run on port 8080.
  4. Configure Varnish to run on port 80.
  5. How the request cycle works is:
    1. All/most HTTP traffic comes in and hits your Varnish server.
    2. Varnish checks it's local cache for that content/URL.
    3. If it exists in cache, Varnish returns it immediately to the user. 
    4. If it doesn't exist in cache, Varnish passes the request to Apache (in the background on port 8080).
    5. Apache returns the content to Varnish.
    6. Varnish returns the content to the user.
    7. All subsequent requests are then served from Varnish cache.
Varnish will reduce your CPU usage massively, so it's a great feature to install and configure correctly (it is worth the effort).

Make sure you clear your varnish cache on deploying a new codebase (otherwise you may notice strange behavior/bugs on your site). The deployment scripts in Part 2 - Prepare for Scalability have an example of clearing varnish cache on deployment.

Here is an example of a Magento configuration for Varnish

That's about it - head on back to the Magento Performance Tips for Scalability post if you missed anything.


Post a Comment