Magento Expert Forum - Improve your Magento experience

Results 1 to 4 of 4

Magento Cache strategy for best performance

  1. #1
    Administrator david's Avatar
    Join Date
    Nov 2012
    Thanked 42 Times in 34 Posts

    Post Magento Cache strategy for best performance

    There are many blog posts about magento cache and how to configure it right.

    In this blog post i want to explain which cache backend (File System, APC, Memcached, Redis) is recommended in which environment (single server, multi server) and how to configure it.

    Understanding Magentos Two-Level Caching

    Magento uses by default the two level cache backend from zend framework.

    Basically its about storing cache records in two backends, in a very fast one (but limited) like APC or Memcached and in a slow one like file system.

    Each cache backend has its features. APC and Memcached are key/value cache backends, they dont support tagging (grouping of cache entries). File system and Redis has tagging support.

    Here you see how two level caching i supposed to work: (Thanks to Fabrizio Branca)

    Explanation of magento cache backends

    File system (var/cache)

    By default, Magento stores its cache entries in the file system, you find the cache in var/cache/.

    This cache backend is fine for small websites with a small cache size but if you get more and more requests through visitors, reading and writing to the file system gets slower and slower from time to time because the cache grows.

    The Magento cache is organized by tags, this means you have cache entries which belongs to a cache group.


    It works by default, you dont need to install additional software.


    Magento clears cache entries by tag e.g. after placing an order or saving a product to make sure the block caches are updated on the store. During clearing entries by cache tag magento has to open each file to check if the cache entry belongs to the cache group. If you have a magento shop with >= 1000 products you will have a cache size of > 50 MB. A 50 MB file system cache has about 3500 entries (files), you can imagine that this is very slow.

    Tips for better file system performance

    1. Use a SSD instead of normal hard disk
    2. Put the var/cache directory in tmpfs

    APC Alternative PHP Cache (Key/Value)

    APC stands for Alternative PHP Cache and is a free and open opcode cache for PHP. Its goal is to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.


    A very fast cache backend.

    With APC on your server you can automatically have duplicate PHP script executions optimized to run more efficiently.

    APC also provides a user cache for storing application data.


    APC does not support tagging, you still have a slow file system as slow level cache.


    PHP APC extension must be installed on server.

    Tips for better performance

    Make sure to give APC enough memory by the parameter apc.shm_size

    Checkout our best practise configuration for php.ini (below)

    Configuration (app/etc/local.xml)


    Settings for php.ini

    apc.enabled = 1
    apc.optimization = 0
    apc.shm_segments = 1
    apc.shm_size = 768M
    apc.ttl = 48000
    apc.user_ttl = 48000
    apc.num_files_hint = 8096
    apc.user_entries_hint = 8096
    apc.mmap_file_mask = /tmp/apc.XXXXXX
    apc.enable_cli = 1
    apc.cache_by_default = 1
    apc.max_file_size = 10M
    apc.include_once_override = 0

    Memcached (Key/Value)

    memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.


    A very fast cache backend.


    Memcached does not support tagging, you still have a slow file system as slow level cache.


    - Memcached server
    - PHP extension for memcached

    Configuration (app/etc/local.xml)

    <!-- apc / memcached / empty=file --> <memcached>
    <!-- memcached cache backend related config -->
    <!-- any number of server nodes can be included -->

    Redis Advanced key-value store with full cache tag support

    This magento cache backend allows you to use a redis server as a central storage. Cache tags
    are supported, we dont need to use the slow level file system cache anymore.
    This magento cache backend is highly recommended in multi server environments where you have more than one webserver.


    Very fast cache backend with fully cache tag support, no slow level file system cache is needed
    Tested on high traffic magento stores with more than 500.000 visitors / day, performance is great and stable.

    - Redis must be installed on the server
    - PHP Extension phpredis must be installed
    - Magento extension Cm_Cache_Backend_Redis must be installed


    1. Install redis (2.4+ required)
    2. Install phpredis
    3. Install the magento extension Cm_Cache_Backend_Redis
    4. Edit your app/etc/local.xml

    <!-- or absolute path to unix socket -->
    <!-- Supports gzip, lzf and snappy -->

    Useful tool for redis

    phpRedisAdmin is a simple web interface to manage Redis databases.


    If you have a small store with a small cache size then APC + file system as second level
    cache would be fine for you. Furthermore i recommend to use a SSD and to put the cache directory into tmpfs.
    If you have a bigger store and a dedicated server you should take a look a redis, its very fast also for big cache sizes > 500 MB. Redis is also the perfect cache solution in a multi server environment where you need a central cache.

    View more threads in the same category:

  2. The Following User Says Thank You to david For This Useful Post:

    Parth Patel (31-07-2013)

  3. #2
    Junior Member
    Join Date
    Jul 2013
    Thanked 0 Times in 0 Posts


    WooooooooooW!!! Very technical and really helpful! Thanks for sharing.

  4. #3
    New member
    Join Date
    Jul 2013
    52 Springvale Pope Pius XII Street Mosta MST2653 Malta
    Thanked 0 Times in 0 Posts


    Yes! agreed one of the best Platform of Ecommerce. Magento plays a vital role for E-Business Companies. This reason is good, but some issues like speed, cache and multisite are suffer mostly magento users. CloudWays bring a best service to Managed Complete platform to support and solve technical issues of Magento.

    Managed Magento Hosting

  5. #4
    Junior Member
    Join Date
    May 2014
    Thanked 1 Time in 1 Post


    That was a great post and the coding was useful too!!!

Similar Threads

  1. Move Magento Cache to RAM by tmpfs
    By david in forum Magento Speed up, Performance and Optimize
    Replies: 4
    Last Post: 13-06-2016, 12:19 PM
  2. How I can check my magento site performance?
    By brent in forum Magento Speed up, Performance and Optimize
    Replies: 4
    Last Post: 26-02-2015, 03:48 PM
  3. Optimizing Magento Performance
    By shunavi in forum Magento Speed up, Performance and Optimize
    Replies: 13
    Last Post: 14-10-2014, 11:14 PM
  4. Adding Cache Support to Magento Blocks
    By sgdev in forum Magento Speed up, Performance and Optimize
    Replies: 2
    Last Post: 29-05-2014, 10:47 AM
  5. How to configuring APC cache for Magento?
    By david in forum Programming & Development
    Replies: 1
    Last Post: 24-03-2013, 09:33 AM

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts