In the process of making your website more optimized, you'll apply various speed-up strategies. So, you'll certainly work with the caches and the Magento clear cache option.
Magento has a built-in cache functionality, such as the full page cache, you can manage directly from the admin panel. Still, you need to do so properly.
In this guide, you'll learn what Magento cache types are there, how the Magento 2 clear cache functionality works, and how to use it.
Let's begin.
Post Contents [hide]
Magento 2 Cache Types
The cache is what helps to optimize speed and overall performance of a website. There is no need to dive deep into the definitions as this concept is well-known to everyone.
Yet, default Magento cache types you get out of the box are certainly worth your attention.
Cache type | Works with: | Cache ID |
---|---|---|
Configuration | Store settings, modules' XML configuration | config |
Layouts | Page layouts | layout |
Block HTML output |
HTML components of pages | block_html |
Collection Data | Collection data files | collections |
Reflection Data | Reflection data of the API interface | reflection |
Database DDL operations | Database queries results | bd_ddl |
Compiled Config | Code compilation results | compiled_config |
EAV types and attributes | Entity types declaration | eav |
Customer Notification | Users' notifications | customer_notification |
Integrations Configuration |
Integration config file | config_integration |
Integrations API Configuration | Integrations API config file | config_integration_api |
Page Cache | full page cache | full_page |
Web Services Configuration | REST, SOAP, and Web API configs | config_webservice |
Translations | Translation files | translate |
As you grow your store, you may start using some third-party cache and caching extensions. So, it's good to know the basics to implement other solutions effectively.
Why Should You Clean Magento Cache?
The cache saves a page, section, or block to load them faster and improve your store speed. Thus it's hard to overestimate the importance of having various caches enabled. But there is the other side.
As you configure your Magento 2 store, the applied changes may not be visible to your customers if they're viewing the cached content. This is not always an advantage since the cached info may be irrelevant or outdated.
That's why you have to resort to the Magento 2 clear cache option. There are two ways to clean the Magento 2 cache and we'll review them in the next sections.
Magento 2 Clear Cache via Admin Panel
First of all, you can clean the Magento 2 cache via the admin panel. To do that, go to System > Cache Management and press the Flush Magento Cache button.
Besides, you can Flush the Cache Storage to remove all cached files including those used by other modules.
You'll find additional Magento 2 clear cache options under the main grid. So, you can also Flush Catalog Images Cache and Flush JavaScript/CSS Cache if your specific task calls for it.
Once the cache is flushed you'll see the success message. And that's about it.
Magento 2 Clear Cache via CLI
If you don't have access to the admin panel at the moment or just prefer working with the code, here is another way. You can also clear Magento 2 cache via CLI. Just run one of the following commands:
bin/magento cache:clean
bin/magento c:c
bin/magento cache:flush
bin/magento c:f
Note: c:c and c:f are shortcuts for cache: clean and cache: flush respectively.
If you clean the cache, only the default Magento caches are affected. When it comes to flushing the cache, it may affect other applications and processes related to caches.
Cleaning the Magento 2 cache is a necessity. But it's still not it.
The disabled cache can cause your website to load slowly which correspondingly drags along some other issues. So, you have to make sure the caches are enabled in the first place.
How to Enable Magento 2 Caches?
Just like with the cache flushing, you can enable any cache type either via the admin panel or CLI.
Enable Magento 2 Cache in the Admin Panel
1. Navigate to System > Cache Management.
2. Choose the cache types you want to enable.
3. Select the Enable option from the Actions dropdown and press the Submit button.
Note: you can enable or disable cache types in the admin panel if your Magento is in developer mode. Otherwise, these options will not be available for you in the dropdown.
Enable Magento 2 Cache via CLI
When it comes to the command line, you can enable the cache regardless of the Magento 2 mode. You just need to run the following command:
php bin/magento cache:enable
However, this command enables all the Magento caches. If you need to enable just a specific type, use the following command:
php bin/magento cache:enable cache_type
Alternatively, you can go to app/etc/env.php and edit the cache_types there. Here you need to set the values to "1" to enable the cache type.
'cache_types' =>
array (
'config' => 1,
'layout' => 1,
'block_html' => 1,
'collections' => 1,
'db_ddl' => 1,
'eav' => 1,
'full_page' => 0,
'translate' => 1,
'config_integration' => 1,
'config_webservice' => 1,
'config_integration_api' => 1,
),
);
How to Disable Magento 2 Caches?
When it comes to disabling Magento 2 caches, you can take all the same steps from the sections above.
If you're working in the admin panel, you can Disable the cache via the Actions dropdown. To disable the cache via CLI, just run this command:
bin/magento cache:disable cache_type
The app/etc/env.php file works here as well. You'll just need to set "0" for the cache types you'd like to disable.
Note: if you want to be notified if any of the caches are disabled configure the disabled cache notifications.
Full Page Cache in Magento
Except for the cache types we've looked through, Magento 2 also offers a full-page cache option. It's another solution that speeds up your website and decreases the server load. It caches not only separate elements on a page but entire pages.
Caching is crucial for effective website management. However, while still using default options, consider implementing other caches, like full page cache.
And when you do, make sure to enable a full-page cache warmer in Magento. It will help you to create the best caching strategy for your store.