How to Clear Magento 2 Cache – A Step by Step Guide

How to Clear Magento 2 Cache – A Step by Step Guide

In the world of eCommerce, your website performance matters as much as your product quality. If you offer top-quality products but the website is lacking in speed or functionality, your store’s performance will be quite limited. The reason is competition. With so many eCommerce stores popping up, the concept of brand loyalty is eroding. Therefore, to beat the competition, you must always be one step ahead.

One way to improve your Magento store’s performance is through the ‘Clear Magento 2 Cache’ function. Cache Clean in Magento 2 ensures loading, formatting, and other issues are resolved, thereby enhancing the user experience. Clearing Magento cache is something every Magento store owner needs to learn.

You don’t need to have a technical background to clear the cache. Instead, all you need is a learning attitude and go through this guide with full attention. This step-by-step guide will help you understand how to effectively clear Magento 2 cache without asking your developer for it.

How to Manually Clear Cache in Magento 2?

This guide will show you the fastest way to clear Magento cache manually. We will show you in this tutorial the easiest practice of clearing Magento 2 cache.

Method 1: Clear Magento 2 Cache via Admin Panel

  • To do that, go to the Admin Panel> System> Cache Management:
  • First, you must specify the types of cache you intend to refresh. For that, cache types will have to be enabled if they are disabled
  • Once you have selected the Cache Types, click drop-down menu and select Enable and click Submit
  • Select the Cache Types again and press the drop-down menu

Clear Magento 2 Cache Refresh and click Submit.

Method 2: Clear the Cache Using Command Line

The second way to clear cache is using the command line. This method removes the need to login to the admin panel. Open up the terminal and follow the below steps:
  • To Enable the cache: php bin/magento cache:enable
  • To Disable the cache: php bin/magento cache:disable
  • To Flush the cache: php bin/magento cache:flush
  • To Clean the cache in the site: php bin/magento cache:clean
You can check more details regarding Magento cache types here.

Method 3: Clear Magento 2 Cache Programmatically

Clearing cache programmatically is one of the best and recommended way to clear cache in order to update the data. Implement the following code to clear Magento 2 cache programmatically:
<?php
use Magento\Framework\App\PageCache\Version;
use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\App\Cache\Frontend\Pool;
protected $cacheTypeList;
protected $cacheFrontendPool;

public function __construct(TypeListInterface $cacheTypeList,
Pool $cacheFrontendPool){
    $this->cacheTypeList = $cacheTypeList;
    $this->cacheFrontendPool = $cacheFrontendPool;

}

public function cacheFunction(Version $subject)
{
  $types = array('config','layout','block_html','collections','reflection','db_ddl','eav','config_integration','config_integration_api','full_page','translate','config_webservice');

    foreach ($types as $type) {
        $this->cacheTypeList->cleanType($type);
    }
    foreach ($this->cacheFrontendPool as $cacheFrontend) {
        $cacheFrontend->getBackend()->clean();
    }
}

How to Flush Magento 2 Cache?

Now go to Admin Panel> System> Cache Management. Over there you will see 2 big buttons on the top. The first one will Flush Magento Cache and the second one will Flush Cache Storage. Click on both to clear Magento Cache and Cache Storage for your website.

By clicking “Flush Magento Cache” all the default Magento Cache items that have Magento tag will be removed.

By clicking “Flush Cache Storage” all the items from Cache with Magento tag and without it will be removed.

Flush Magento 2 Cache

Additional Cache Management:

Magento 2.0 has another method as well to Flush Catalog Images Cache and JavaScript/CSS Cache.

Navigate to Admin Panel> System> Cache Management and you will see the options at the bottom of the page as shown below.

Magento 2 Cache management The first option will remove the catalog images from all sections such as media/catalog/product/cache. The second option will remove the JavaScript copy and CSS files from the Cache of your Magento 2 store

Enable Magento 2 Full Page Cache

To improve your website performance and webpages loading speed, you can enable Full Page Cache option.
  • Go to Admin Panel> Stores> Configuration> Advanced> System> Full Page Cache
  • Select one of the options required to Built-In Cache or Varnish Cache
Magento Full Page Cache Research has revealed that Built-In Applications help your pages get 4 to 9 times faster loading speeds compared to Varnish Caching.

Magento 2 Clean Cache vs. Flush:

You can run both the commands to remove played out items from your website: clean and flush Magento 2 cache. However, it is important that you learn the difference:

Magento 2 Clean cache:

Since it deletes all enabled cache types, disabled cache types are not cleaned from Magento 2

Flush Cache

Flushing a cache type purges the cache storage, which might affect other processes applications that are using the same storage. e.g. other websites. Flush cache types if you’ve already tried cleaning the cache and you’re still having issues that you cannot isolate.

How to Enable/Disable Cache Types?

  • Navigate to Admin Panel> Stores> Configuration
  • Check the cache types and click the upper left drop-down menu
  • Now, select Enable or Disable and click Submit button

Clear Magento 2 Cache

Conclusion

Congratulations! You have successfully cleared Magento 2 cache and learned to do it all by yourself. Now you can easily add your content and reflect them on your front-end store without any over complicated procedures. If you run into trouble when clearing the cache, reach out to us. Our Magento development experts will address your queries promptly and to your satisfaction.

This blog was created with FME's SEO-friendly blog