
Cache Optimization Strategy for Magento 2 Performance
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.
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.
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.
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.
Server- Software Recommendation
The official Magento guide for speed optimization recommends the following software to be used on a server for Magento 2 performance tuning:
- Varnish cache
- PHP 7
- (Enterprise only) Use the Solr & Solr Search Adapter
- Nginx and PHP-FPM
For multi-server deployment and for those who are planning for scaling their business, the official Magento guide suggests the following-
- Redis for sessions (from 2.0.6+)
- A separate Redis instance as your default cache
- Do not use this instance for page cache
Server- Composer Optimization
Update the autoloader using composer after generating class by running the following command:
setup:di:compile
To generate an optimized composer class map, which supports fast auto loading, run the below mentioned composer command:
composer dump-autoload -o –apcu
Server- PHP Optimization
For maximum performance, we recommend to enable and tune PHP Magento Opcache.
Include the following to edit your opcache.ini file
opcache.enable_cli=1
opcache.memory_consumption=512
opcache.max_accelerated_files=100000
opcache.validate_timestamps=0
opcache.consistency_checks=0
Always consider the size of Magento’s 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’t have many extensions or customization installed.
opcache.memory_consumption=64
opcache.max_accelerated_files=60000
You can get maximum performance by enabling PHP APCu extension. Include the following in your apcu.ini file-
extension=apcu.so
[apcu]
apc.enabled = 1
Server- Redis Configuration and Tuning
Sessions
Take into account how sessions are flushed from the cache and merchant cart
Caches
Specify a memory size so that you can use skus, product pages and content pages effectively.
Application- Performance Improvements
To improve application side performance, follow the below mentioned instructions:
In default developer mode, go to the Admin, and change the following settings for storefront asset optimization:
Stores -> Configuration -> Advanced -> Developer
Now go to Stores -> Configuration -> Sales -> Sales Emails
Set all indexers to “Update on Schedule” mode under Stores -> Index Management
Switch to Production Mode
Run the below mentioned command to switch to production mode.
bin/magento deploy:mode:set production
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’t 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.
Still have any question? Leave it in the comment box below and we will try our best to sort it out.
Also Read: AMP with Magento2: Get to Know How Fast Loading Pages Can Win Customers