Table of Contents
Magento 2 uses caching so that your store is faster and smoother by temporarily keeping data like layouts, configurations, and HTML content. But whenever you do something on your site and you don’t see the changes applied directly, then you might need to clear the cache.
You can manage cache in Magento 2 either by the command line (best suited for developers) or the Admin Panel (best suited for beginners). In this article, we will show you how to flush the cache, check its status, and enable it when needed.
What Is Cache in Magento 2?
Magento 2 stores different types of cache to improve speed and performance, including:
- Configuration cache – saves settings and system configs
- Layout cache – stores page layout data
- Block HTML cache – saves HTML output for page blocks
- Collections cache – optimizes the retrieval of data from the database.
You may find more information about cache types here.
Method 1: Flush Cache Using the Command Line
Steps:
- Connect to your server via SSH.
- Navigate to your Magento 2 root directory:
cd /var/www/html/magento2 - Clean or flush the cache:
To clean the cache (recommended):
php bin/magento cache:cleanTo flush all cache (including external systems):
php bin/magento cache:flushUse cache:clean when you wish Magento to rebuild only what’s needed. Use cache:flush to completely clear everything, including third-party cache systems like Varnish.
Method 2: Flush Cache Using the Admin Panel
Steps:
- Log in to the Magento Admin Panel.
- Go to System > Cache Management.
- You’ll see a list of cache types and their status.
- Click Flush Magento Cache to clear internal cache.
- Click Flush Cache Storage to clear all caches, including external ones.
- Or select specific cache types, then click Submit to clean only those.
How to Check Cache Status via Command Line
You can easily verify which cache types are disabled or enabled.
Command:
php bin/magento cache:statusYou will see a list with each cache type and its current state (enabled or disabled). For example:
config: 1
layout: 0
block_html: 11 = enabled and 0 = disabled.
How to Enable Cache in Magento 2 Using the Command Line
If you want to enable a disabled cache type:
To enable a specific cache type:
php bin/magento cache:enable layoutTo enable all cache types at once:
php bin/magento cache:enableHow to Enable Cache Using the Admin Panel
Steps:
- Log in to the Magento Admin Panel.
- Go to System > Cache Management.
- Check the boxes next to the disabled cache types.
- From the Actions dropdown, choose Enable.
- Click Submit to apply changes.
When Should You Flush or Enable Cache in Magento 2?
- After you install or update extensions or themes
- After you change store settings or configurations
- When your site is not showing recent updates
- After you deploy new code or files
Conclusion
Magento 2’s caching system is a powerful tool that can improve the site’s performance but must be managed appropriately. Whether managing through the terminal or the admin interface, having the ability to flush, check, and enable cache types will save time and headaches.
If you are new, the Admin Panel is user-friendly and safe. If you are experienced or you have a larger site, the command line is more versatile and quicker.