• Solution. Support. Expertise
  • +43 664 635 1238
  • +1 647 947 9546
  • info@tdwebservices.com
Magento Two Level Caching SystemsMagento Two Level Caching SystemsMagento Two Level Caching SystemsMagento Two Level Caching Systems
  • Hosting
    • Hosting
      • Business Hosting
      • Enterprise Hosting
      • TDWS VPS
      • Managed WordPress Hosting
      • Highly Optimized WordPress Hosting
      • Laravel Hosting
      • Odoo Hosting
      • Moodle Hosting
      • TDWS Reseller Plans
    • E-Commerce Solutions
      • Managed WooCommerce Hosting
      • Highly Optimized WooCommerce Hosting
      • Magento Hosting
      • PrestaShop Hosting
      • OpenCart Hosting
    • Dedicated Servers
      • Gaming Servers
    • TDWS Global Monitoring System
      • Server Monitoring
      • Network Monitoring
      • Application Monitoring
      • Database Monitoring
      • Cloud Monitoring
      • Container Monitoring
      • Storage Monitoring
  • Cloud
    • TDWS Cloud
      • TDWS Cloud Servers
      • TDWS CloudSites
      • TDWS Box Cloud
      • TDWS Virtual Private Cloud
      • TDWS Cloud Drive
    • TDWS Private Cloud
      • KVM Hypervisor Private Cloud
      • Xen Hypervisor Private Cloud
      • Microsoft Hyper-V Private Cloud
      • VMware ESXi Private Cloud
      • VMware Public Cloud Servers
    • Services
      • DB as a Service
      • Disaster Recovery as a Service
    • Other
      • TDWS Cloud Infrastructure
      • TDWS Hybrid Cloud
  • Insights
    • Small Business
    • Knowledge Base
    • Cloud Computing
    • Expert Opinion
    • Industry debates
    • Thought Leadership
  • About Us
    • Why Us
    • Data Centers
    • Affiliate
    • TDWS Channel Partners
    • Contact Us
    • TDWS Customer Reviews
    • TDWS Video
    • Legal
      • TD Web Services Acceptable Use Policy (“AUP”)
      • TDAG DMCA Notice Policy
      • TDAG Privacy Policy
      • Master Service Agreement
      • Service Level Agreement
Login
✕
GHOST: glibc vulnerability (CVE-2015-0235)
1 February 2015
Installing WordPress on Centos 6
2 February 2015

Magento Two Level Caching Systems

Published by TDWS Technical Support on 1 February 2015
Categories
  • Knowledge Base
Tags
  • Magento
  • Magento Optimisation

The default setting on Magento enables it to use a two level cache backends from the zend framework. This means that the system stores its cache records in two different backends where one is the faster and yet limited one while the other is slower. The faster alternatives include APC and Memcached while the file system is the slow one. The backends have unique features that make choosing them a rather important part of the process. The APC and Memcached for example do not support grouping the cache entries, as they are key/value cache backends. The files system and Redis however allow you to group the cache entries.

The two level caching system and how it works:

Magento Two Level Caching Overview

 

The Magento backends

File system

The Magento default setting has it storing its cache entries in the file system and thus they can be found in var/cache/. The file system works just fine for websites that do not have much traffic but once the requests increase you may be unable to read and write in the file system. In this case however, the caches are organized by groups and may thus be easy to read and write. The main advantage of the file system is that it is in the default setting and thus you do not have to install any additional programs to operate it.

The disadvantage on the other hand is that if you want to clear cache Magento will have to go through each cache group file by file to check the tags before clearing since it clears by tags. Thus if you have too many cache entries it could take forever for Magento to actually clear them all. In order to get the system to work more effectively you may want to use SSD instead of the usual hard disk. Also, you could put the var/cache/ directory in tmpfs.

APC

The Alternative PHP Cache (APC) is a key/value cache, that is free and open meaning that it is dedicated to provided an open framework where the PHP intermediate code can undergo optimization. The main advantage of this caching alternative is the speed at which it works. The APC allows you to have duplicate PHP script extensions running more efficiently in an automated system. It also enables you to store application data.

The disadvantage on the other hand is that is does not support tagging and as such you will end up having a slow system as is with the file system. The APC also requires installation of the PHP APC extension on the server as it is not an automatic default setting. For this alternative to perform better you may need to give it a larger memory space by the parameter “apc.shm_size”. You could also improve it by following the prompts below.

Configuration (app/etc/local.xml)

<global>
...
<cache>
<backend>apc</backend>
<prefix>mgt_</prefix>
</cache>
...
</global>

 

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

This is a high performance caching system that has a well distributed memory. This system operates by alleviating the database load thus making it very useful for busy websites that use many web applications. Its main advantage is that it is very fast, compared to the other caching backends. It however does not support tagging and will thus give you a very slow file system. To work, it will require a Memcached server and its PHP extension.

Configuration (app/etc/local.xml)

<global>
...
<cache>
<backend>memcached</backend><!-- apc / memcached / empty=file -->
<memcached><!-- memcached cache backend related config -->
<servers><!-- any number of server nodes can be included -->
<server>
<host><![CDATA[127.0.0.1]]></host>
<port><![CDATA[11211]]></port>
<persistent><![CDATA[1]]></persistent>
</server>
</servers>
<compression><![CDATA[0]]></compression>
<cache_dir><![CDATA[]]></cache_dir>
<hashed_directory_level><![CDATA[]]></hashed_directory_level>
<hashed_directory_umask><![CDATA[]]></hashed_directory_umask>
<file_name_prefix><![CDATA[]]></file_name_prefix>
</memcached>
</cache>
...
</global>

 

Redis

This particular backend allows for a redis server to be your central storage. It also allows tagging, making it the only backed that will eliminate the slow file system. This means that it is an ideal backend especially for situations where you are using multiple web servers. The main advantage is the elimination of a slow file system and the fact that it has passed numerous trials on busy websites. It is very fast, stable and effective even with a record of half a million visitors per day.

To use this backend, you must install Redis on the server and have the PHP extension phpredis. You also have to install the Magento extension “Cm_Cache_Backend_Redis”

To install this backend,

First install redis version 2.4+, then install phpredis. After this, you have to install the magento extension “Cm_Cache_Backend_Redis” and finally edit your app/etc/local.xml

<global>
...
<cache>
<backend>Cm_Cache_Backend_Redis</backend>
<backend_options>
<server>127.0.0.1</server> <!-- or absolute path to unix socket -->
<port>6379</port>
<persistent></persistent>
<database>0</database>
<password></password>
<force_standalone>0</force_standalone>
<connect_retries>1</connect_retries>
<automatic_cleaning_factor>0</automatic_cleaning_factor>
<compress_data>1</compress_data>
<compress_tags>1</compress_tags>
<compress_threshold>20480</compress_threshold>
<compression_lib>gzip</compression_lib> <!-- Supports gzip, lzf and snappy -->
</backend_options>
</cache>
...
</global>

 

You will also need to install phpRedisAdmin, a useful tool that manages Redis databases.

Conclusion

If you are working with a small cache size then the APC and a file system will work best as your second level cache. This will however be optimized if you use the SSD and have your directory in tmpfs. But for bigger stores with larger cache sizes redis is the best option you could get.

Share
0
TDWS Technical Support
TDWS Technical Support

Related posts

15 June 2021

Why Upgrade Your Site to PHP 7.x


Read more
27 May 2021

Common Causes Why is WordPress Slow


Read more
27 May 2019

WordPress Acceleration using NginX Reverse Proxy & Caching


Read more
12 March 2019

How to Switch Your Domain Name Without Damaging Your Site’s SEO


Read more
10 March 2019

How to Use the cPanel/WHM Transfer Accounts Tool


Read more
6 June 2018

How to Change WordPress password using phpMyAdmin or MySQL


Read more
13 April 2018

How to Transfer WordPress Site to a New Domain


Read more
1 February 2017

The ABCD of Cloud Computing


Read more

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Our Services

  • Business Hosting
  • TDWS VPS
  • Dedicated Servers
  • E-Commerce Solutions
  • Enterprise Hosting
  • Managed WordPress Hosting
  • Highly Optimized WordPress Hosting
  • SSL Certificates

TDWS Cloud

  • TDWS Cloud Servers
  • TDWS CloudSites
  • VMware Public Cloud Servers
  • VMware ESXi Private Cloud
  • Microsoft Hyper-V Private Cloud
  • TDWS Virtual Private Cloud
  • Hybrid Cloud
  • Cloud Infrastructure

Recent Posts

  • Ensuring Security In Public Cloud Hosting
  • How Product Reviews Can Lead To More Sales For Your Online Store
  • How Can Adaptive Website Design Increase Your Visitor Count?
  • The Anatomy of a Profitable eCommerce Sales Funnel for Small Businesses
  • Contests and Giveaways in WordPress. Ultimate Guide. [+ Contest Prize Ideas]

About Us

  • About Us
  • Why Us
  • Affiliate
  • Contact Us
  • Data Centers
© 2021 TD Web Services. All Rights Reserved.