{"id":2279,"date":"2019-01-22T19:10:04","date_gmt":"2019-01-22T13:40:04","guid":{"rendered":"https:\/\/www.idslogic.com\/blog\/?p=2279"},"modified":"2025-02-24T13:13:35","modified_gmt":"2025-02-24T07:43:35","slug":"cache-optimization-strategy-for-magento-2-performance","status":"publish","type":"post","link":"https:\/\/www.idslogic.com\/blog\/cache-optimization-strategy-for-magento-2-performance","title":{"rendered":"Cache Optimization Strategy for Magento 2 Performance"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_72 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.idslogic.com\/blog\/cache-optimization-strategy-for-magento-2-performance\/#Server-_Software_Recommendation\" title=\"Server- Software Recommendation\">Server- Software Recommendation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.idslogic.com\/blog\/cache-optimization-strategy-for-magento-2-performance\/#Server-_Composer_Optimization\" title=\"Server- Composer Optimization\">Server- Composer Optimization<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.idslogic.com\/blog\/cache-optimization-strategy-for-magento-2-performance\/#Server-_PHP_Optimization\" title=\"Server- PHP Optimization\">Server- PHP Optimization<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.idslogic.com\/blog\/cache-optimization-strategy-for-magento-2-performance\/#Server-_Redis_Configuration_and_Tuning\" title=\"Server- Redis Configuration and Tuning\">Server- Redis Configuration and Tuning<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.idslogic.com\/blog\/cache-optimization-strategy-for-magento-2-performance\/#Application-_Performance_Improvements\" title=\"Application- Performance Improvements\">Application- Performance Improvements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.idslogic.com\/blog\/cache-optimization-strategy-for-magento-2-performance\/#Switch_to_Production_Mode\" title=\"Switch to Production Mode\">Switch to Production Mode<\/a><\/li><\/ul><\/nav><\/div>\n<p><span style=\"font-size: 14pt;\">Magento is the epitome of Ecommerce. One of the biggest selling points of Magento is that it provides an all-in-one solution and flexibility. It is perhaps the most popular platform available to ecommerce website users as well as online store owners. The exceptional Magento 2 optimization capability makes this platform one of the popular ones among users.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">Magento 2 is the second version of Magento platform, consisting of cutting-edge technology, advanced features and more flexibility. In the contemporary era where website speed matters a lot for high conversion rate, importance of Magento 2 performance optimization is evident. It is faster, less resource hungry, and easy to optimize for high speed as compared to Magento 1.X versions and when it comes to speed optimization it needs a different approach than its former version. Added to this, Magento 2 CPRA is there to use for keeping security compliances as required.\u00a0<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">Even though is it a very successful ecommerce platform, it does have its own shortcomings. In this blog post, we are going to shed light on how to optimize Magento 2 performance using cache strategy along with explaining optimizing page cache for Magento.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">As we all know, caching is the mightiest mechanism to serve your website content faster. Magento 2 supports several caching solutions and offers a lot of new performance features out-of-the-box. For example, you get native support for Varnish, Redis, and full-page caching in Magento 2, while in the first version, all these features were only available through customization and extensions. Below, we have explained the methods for Magento optimization tuning to make your Magento 2 store load faster.<\/span><\/p>\n<hr \/>\n<h3><span class=\"ez-toc-section\" id=\"Server-_Software_Recommendation\"><\/span><span style=\"color: #993300;\"><strong>Server- Software Recommendation<\/strong><\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-size: 14pt;\">The official Magento guide for speed optimization recommends the following software to be used on a server for <a href=\"\/blog\/how-to-revamp-the-performance-of-your-magento-store\">Magento 2 performance tuning<\/a>:<\/span><\/p>\n<ol>\n<li><span style=\"font-size: 14pt;\">Varnish cache<\/span><\/li>\n<li><span style=\"font-size: 14pt;\">PHP 7<\/span><\/li>\n<li><span style=\"font-size: 14pt;\">(Enterprise only) Use the Solr &amp; Solr Search Adapter<\/span><\/li>\n<li><span style=\"font-size: 14pt;\">Nginx and PHP-FPM<\/span><\/li>\n<\/ol>\n<p><span style=\"font-size: 14pt;\">For multi-server deployment and for those who are planning for scaling their business, the official Magento guide suggests the following-<\/span><\/p>\n<ol>\n<li><span style=\"font-size: 14pt;\">Redis for sessions (from 2.0.6+)<\/span><\/li>\n<li><span style=\"font-size: 14pt;\">A separate Redis instance as your default cache<\/span><\/li>\n<li><span style=\"font-size: 14pt;\">Do not use this instance for page cache<\/span><\/li>\n<\/ol>\n<hr \/>\n<h3><span class=\"ez-toc-section\" id=\"Server-_Composer_Optimization\"><\/span><span style=\"color: #993300;\"><strong>Server- Composer Optimization<\/strong><\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-size: 14pt;\">Update the autoloader using composer after generating class by running the following command:<\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 setup:di:compile<\/em><\/span><\/p>\n<p><span style=\"font-size: 14pt;\">To generate an optimized composer class map, which supports fast auto loading, run the below mentioned composer command:<\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0composer dump-autoload -o \u2013apcu<\/em><\/span><\/p>\n<hr \/>\n<h3><span class=\"ez-toc-section\" id=\"Server-_PHP_Optimization\"><\/span><span style=\"color: #993300;\"><strong>Server- PHP Optimization<\/strong><\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-size: 14pt;\">For maximum performance, we recommend to enable and tune PHP Magento Opcache.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">Include the following to edit your <em>opcache.ini <\/em>file<\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 opcache.enable_cli=1<\/em><\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 opcache.memory_consumption=512<\/em><\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 opcache.max_accelerated_files=100000<\/em><\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 opcache.validate_timestamps=0<\/em><\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 opcache.consistency_checks=0<\/em><\/span><\/p>\n<p><span style=\"font-size: 14pt;\">Always consider the size of Magento\u2019s code base and extension when you are tuning the memory allocation for PHP opcache. Use the following setting, if you are on a low memory machine and don\u2019t have many extensions or customization installed.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 opcache.memory_consumption=64<\/em><\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 opcache.max_accelerated_files=60000<\/em><\/span><\/p>\n<p><span style=\"font-size: 14pt;\">You can get maximum performance by enabling PHP APCu extension. Include the following in your <em>apcu.ini <\/em>file-<\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 extension=apcu.so<\/em><\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [apcu]<\/em><\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 apc.enabled = 1<\/em><\/span><\/p>\n<hr \/>\n<h3><span class=\"ez-toc-section\" id=\"Server-_Redis_Configuration_and_Tuning\"><\/span><span style=\"color: #993300;\"><strong>Server- Redis Configuration and Tuning<\/strong><\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"color: #003366;\"><strong>Sessions<\/strong><\/span><\/p>\n<p><span style=\"font-size: 14pt;\">Take into account how sessions are flushed from the cache and merchant cart\u00a0<\/span><\/p>\n<p><span style=\"color: #003366;\"><strong>Caches<\/strong><\/span><\/p>\n<p><span style=\"font-size: 14pt;\">Specify a memory size so that you can use skus, product pages and content pages effectively.<\/span><\/p>\n<hr \/>\n<h3><span class=\"ez-toc-section\" id=\"Application-_Performance_Improvements\"><\/span><span style=\"color: #993300;\"><strong>Application- Performance Improvements<\/strong><\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-size: 14pt;\">To improve application side performance, follow the below mentioned instructions:<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">In default developer mode, go to the Admin, and change the following settings for storefront asset optimization:<\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><strong>Stores -&gt; Configuration -&gt; Advanced -&gt; Developer<\/strong><\/span><\/p>\n<p><a href=\"https:\/\/www.idslogic.com\/blog\/wp-content\/uploads\/2019\/01\/Screenshot_2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2281 size-full\" src=\"https:\/\/www.idslogic.com\/blog\/wp-content\/uploads\/2019\/01\/Screenshot_2.png\" alt=\"screenshot 2\" width=\"621\" height=\"288\" srcset=\"https:\/\/www.idslogic.com\/blog\/wp-content\/uploads\/2019\/01\/Screenshot_2.png 621w, https:\/\/www.idslogic.com\/blog\/wp-content\/uploads\/2019\/01\/Screenshot_2-300x139.png 300w, https:\/\/www.idslogic.com\/blog\/wp-content\/uploads\/2019\/01\/Screenshot_2-560x260.png 560w\" sizes=\"auto, (max-width: 621px) 100vw, 621px\" \/><\/a><\/p>\n<p><span style=\"font-size: 14pt;\">Now go to <span style=\"color: #008080;\"><strong>Stores -&gt; Configuration -&gt; Sales -&gt; Sales Emails<\/strong><\/span><\/span><\/p>\n<p><a href=\"https:\/\/www.idslogic.com\/blog\/wp-content\/uploads\/2019\/01\/Screenshot_1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-2280 size-full alignleft\" src=\"https:\/\/www.idslogic.com\/blog\/wp-content\/uploads\/2019\/01\/Screenshot_1.png\" alt=\"screenshot 1\" width=\"617\" height=\"90\" srcset=\"https:\/\/www.idslogic.com\/blog\/wp-content\/uploads\/2019\/01\/Screenshot_1.png 617w, https:\/\/www.idslogic.com\/blog\/wp-content\/uploads\/2019\/01\/Screenshot_1-300x44.png 300w, https:\/\/www.idslogic.com\/blog\/wp-content\/uploads\/2019\/01\/Screenshot_1-560x82.png 560w\" sizes=\"auto, (max-width: 617px) 100vw, 617px\" \/><\/a><\/p>\n<p><span style=\"font-size: 14pt;\">Set all indexers to \u201cUpdate on Schedule\u201d mode under <strong>Stores -&gt; Index Management <\/strong><\/span><\/p>\n<hr \/>\n<h3><span class=\"ez-toc-section\" id=\"Switch_to_Production_Mode\"><\/span><span style=\"color: #993300;\"><strong>Switch to Production Mode<\/strong><\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-size: 14pt;\">Run the below mentioned command to switch to production mode.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 bin\/magento deploy:mode:set production<\/em><\/span><\/p>\n<p><span style=\"font-size: 14pt;\">Important thing to notice here is, no matter what cache backend you are using for Magento 2, the first visitor will see an uncached page. An uncached page takes more time to load as compared to cached web page. Therefore, it is highly recommended to visit these pages by yourself before your customers do. And the best thing is it really doesn\u2019t matter if the page is visited by a person or a bot. We hope the Magento full page cache auto generation explained in this blog here will provide you a better understanding of Magento cache.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">Still have any question? Leave it in the comment box below and we will try our best to sort it out.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><strong>Also Read: <strong><span style=\"color: #f00717;\"><a style=\"color: #f00717;\" href=\"\/blog\/amp-with-magento2-get-to-know-how-fast-loading-pages-can-win-customers\">AMP with Magento2: Get to Know How Fast Loading Pages Can Win Customers<\/a><\/span><\/strong><\/strong><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento is the epitome of Ecommerce. One of the biggest selling points of Magento is that it provides an all-in-one solution and flexibility. It is perhaps the most popular platform available to ecommerce website users as well as online store&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2282,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[171,550],"tags":[705,442,704],"class_list":["post-2279","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ecommerce-website-development","category-magento","tag-magento-2-cache-strategy","tag-magento-2-development","tag-magento-2-optimization"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/posts\/2279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/comments?post=2279"}],"version-history":[{"count":18,"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/posts\/2279\/revisions"}],"predecessor-version":[{"id":10494,"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/posts\/2279\/revisions\/10494"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/media\/2282"}],"wp:attachment":[{"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/media?parent=2279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/categories?post=2279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.idslogic.com\/blog\/wp-json\/wp\/v2\/tags?post=2279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}