In the process of making your website more optimized, you'll get to apply various speed-up strategies. That said, you'll certainly work with the Magento 2 clear cache option.
Although Magento has a built-in cache functionality, such as the full page cache, you need to manage the caches properly. In this guide, you'll learn how the Magento clear cache functionality works and how to use it.
So, let's begin.
Post Contents [hide]
Why Should You Clean Magento Cache?
As you might know, 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. That's why you'll have to resort to Magento 2 clear cache option.
There are two ways to clean Magento 2 cache.
Magento 2 Clear Cache via Admin Panel
First of all, you can clean Magento 2 cache via the admin panel. To do that, go to Admin Panel > System > Cache Management and press the Flush Magento Cache button.
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.
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
To enable Magento 2 cache in the admin:
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 below 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, or to "0" to disable it.
'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,
),
);
Having the Magento 2 cache enabled helps to prevent unwanted issues is one thing. But it is also useful to receive the disabled cache notifications to know if the caches work properly.