Clearing the cache in Magento 2 is an important task to make sure your online store works well and shows any updates you make. Cache clear helps make web pages load faster by storing commonly used data. But sometimes, the stored data can be different from the new changes you made.
In this guide, we’ll learn why clearing the cache is important, how to do it in Magento 2, and some things to remember for a smooth website. By understanding how to clear the cache in Magento 2, you can keep your store running smoothly and give your customers a good experience. Let’s dive in.
What is the Magento 2 cache?
The cache in Magento 2 is a special storage area on the server that stores web pages, scripts, and other resources. It helps make these elements quickly accessible so that they can be shown to visitors faster. Caching improves the speed of loading pages, especially during periods of high traffic.
The Magento 2 cache plays a crucial role in optimizing the performance of a Magento 2 website. Magento 2 uses different types of caching, such as Minification, Varnish, and Redis, to improve the loading speed and responsiveness of web pages.
When Magento 2 starts, the cache collects configuration files from all the modules installed on the website. These files contain information about different parts of the website, such as layout, block definitions, and system configurations. Magento merges these files and saves the merged configuration to the cache.
However, caching can sometimes cause a problem. It can make the cached version of a page different from the updated content on the website. To solve this issue, Magento has features that let you refresh the cache when you make changes to your online store. After you make changes to your website, you need to clear the cache so that the updated content can be seen on the front of your website. It’s important to manage your caches properly to maintain good performance on your Magento website. You may need to clear, enable, or disable your caches as needed.
How To Clear Cache In Magento 2?
You can clear the cache in Magento 2 successfully if you follow these 2 steps.
Step 1: Go to the admin panel, navigate to SYSTEM, and choose Cache Management (under Tools)
(Admin Panel => SYSTEM => Cache Management)
Step 2: Clear the cache as you want. Select the cache types you want to refresh, there are 3 main types:
The 1st case: Refreshing a certain cache
If you just want to refresh/ clear a specific cache, you must tick a checkbox (at the beginning of the row) that is correlative with that cache. Then, you choose “Refresh” on the drop-down and click on the “Submit” button to complete.
Similarly, if you want to clear several caches, just mark multiple checkboxes, then submit selected ones to refresh.
The 2nd case: Flushing All Magento Caches
In case you want to refresh the whole cache list – delete all items in the default Magento cache (var/cache) according to their associated Magento tags, you just need to click on the “Flush Magento Cache” button.
The 3rd case: Flushing Catalog Images/ Javascript/ CSS/ Static Files Caches
Flush Catalog Images Cache: in order to discard all automatically watermarked and resized catalog images stored at media/catalog/product/cache.
Flush Javascript/ CSS Cache: with the aim of clearing away all merged copies of Javascript/ CSS files from the cache.
To clear these types of cache, you must click on the buttons under the “Additional Cache Management” section.
Remember that after clearing a cache, you must refresh your browser to make sure that you can see the most recent changes.
Difference Between Magento 2 Cache Clean And Flush
The main difference between a cache flush and a cache clean in Magento 2 lies in the scope of their actions and the impact on other processes.
When you perform a cache flush in Magento 2, all the data stored in the cache is completely removed. This includes all enabled caches, and it may also affect the performance of other processes that are using the same storage, such as Redis, and other websites,… As a result, a cache flush has a broader impact and can potentially impact the performance of other applications or services running on the server.
On the other hand, a cache clean in Magento 2 specifically targets the enabled caches within Magento itself. This means it deletes the data stored in these caches while leaving other disabled cache types unaffected. The scope of a cache clean is limited to the caching mechanisms provided by Magento, and it doesn’t have a direct impact on other applications or services running on the server.
In summary, a cache flush removes all data from the cache, including enabled caches, and may impact other processes using the same storage. A cache clean, on the other hand, specifically clears enabled caches within Magento without affecting other server processes.
Enable Magento 2 Cache
Here’s how to enable caches from the Magento Admin panel:
Step 1: From the Magento Admin panel, go to System and click Cache Management.
Step 2: Select the cache type you want to enable (e.g., Layouts, Configuration).
Step 3: Ensure that you set Enable on the top-left menu
Step 4: Click Submit.
The output will be like this.
Disable Magento 2 Cache
Step 1: Magento Admin panel, navigate to System and choose Cache Management.
Step 2: Select the cache type you want to disable (e.g., Cache Import Products).
Step 3: Ensure that you set Disable on the top-left menu
Step 4: Click Submit.
Here is the output:
FAQ
1. What happens when I flush the Magento cache?
Flushing the cache in Magento clears all Magento stores’ cache, regardless of their Commerce tag. This action affects all Magento stores that share the same cache storage, ensuring a complete cache clearance. In the process, any cached files used by other applications are also removed.
2. How often should I clear my cache in Magento 2?
It depends on your privacy concerns and your website’s performance. It’s generally suggested to clear them if your website experiences slow browsing, website loading issues, outdated information, or needs to free up storage. Flush cache for extension installation/removal, Magento Commerce installation, and Open Source Commerce version upgrade. Remember to avoid peak times to prevent website downtime.
3. Does clearing the cache improve performance?
Deleting the cache and cookies data regularly helps to troubleshoot, increase the loading time of web pages, and increase the performance of your website.