logo company

Contact us:
+(48) 572 970 235 or Book a call
Guides Magento Optimization Website Performance

How to Flush Magento Cache? A Step-by-Step Guide

0%
How to Flush Magento Cache? A Step-by-Step Guide

Magento cache temporarily stores data that helps pages to load more quickly. Out of the box, Magento 2 enables cache types like full-page cache and Varnish cache. Both are integral to optimizing the performance of your e-commerce website.

If you fail to flush the cache regularly, you’ll have technical, UX, and SEO issues. That’s why below we’ll guide you through the Magento cache management steps.

What Happens if You Don't Flush Magento Cache?

A stale cache can negatively affect the user experience by slowing down the site's loading and giving customers old information. Customers may see old promotions or prices and be unhappy when they are no longer valid. They also won't see new themes or layouts.

As a rule, you should flush the cache:

  • Every time you make changes to your store.
  • Before you deploy a new version to a live site.
  • Anytime your site is performing poorly or behaving unexpectedly.

3 Methods to Flush Cache Storage in Magento

Depending on the circumstances, you can flush the cache using three primary methods.

1. Flushing Cache via Magento Admin Panel

Using the Admin panel to flush the cache is appropriate whenever you need to reflect changes on the front end immediately. These changes could include product details or content. It’s also fitting for the times when you adjust configurations in the Admin panel or install new modules.

Here are the step-by-step instructions.

  1. Log into the Magento Admin Panel.
  2. Find System > Cache Management.
  3. In the Cache Management window, find Flush Magento Cache.

You can flush the entire cache storage, or you can select cache types to refresh, such as Layout 1, Block, HTML 1, Collections, Database, etc.

  1. You'll receive a message that the cache has been flushed.

2. Flushing Cache via SSH/CLI

Another way to flush the cache is through SSH with the help of a PHP bin Magento cache flush command. Using this method requires access to the server.

 

Why Use SSH/CLI for Flushing Cache?

Using SSH/CLI has several advantages, including:

  • Not having to log in to the Admin Panel.
  • Efficiency because you don't have to do manual tasks or configure the cache.
 
Step-by-Step Instructions

Here are the step-by-step instructions for flushing Magento cache using SSH/CLI.

  1. Log into the server via SSH.
  2. Run the following command from your root folder:

php -r 'require "app/Mage.php"; Mage::app()->getCacheInstance()->flush();'

When you run the command, note that using "cache:clean" is different from using "cache:flush." A cache clean removes only the Magento-enabled caches, while a cache flush removes all the data from the cache, including disabled cache types, which may impact other server processes.

3. Flushing Varnish Cache

Varnish cache is an open-source HTTP accelerator that caches content served by the web server. Varnish enables your e-commerce store to handle more traffic while still performing well. You need to have proper web server configuration to effectively use it with Magento.

 

How to Flush Varnish Cache in Magento

You can flush the Varnish cache for a specific domain, file type, or in its entirety. You can also use the backend panel or the command line. Here are some examples of commands for flushing cache types or the whole.

  • To flush a single domain: varnishadm "ban req.http.host ~ www.mydomain.com"
  • To flush a specific file type of a single domain: varnishadm "ban req.http.host ~ www.mydomain.com" && req.url ~ .css"
  • To flush the whole cache: varnishadm "ban req.url ~ ."

Enabling and Disabling Cache for Troubleshooting

Cache management may also involve disabling or enabling cache for troubleshooting purposes. For example, you might need to temporarily disable the cache to determine if a website issue is linked to cache functionality.

To do that:

  1. First, check if the cache is on or off via a bin Magento cache status command: bin/magento cache:status 
  2. If the cache is on, you can disable it by typing: bin/magento cache:disable 
  3. Enable it back through a similar bin magento cache enable command: bin/magento cache:enable

FAQs

 

What is the difference between cache:flush and cache:clean in Magento?

Cache clean only affects Magento-related caches, while cache flush or flush cash storage affects all storage.

 

How often should I flush the Magento cache?

Flush the cache when adding or removing extensions or new modules, or making changes or updates to your store.

 

Can I automate Magento cache flushing?

Yes, several tools exist to automate the cache flushing. They are available as extensions. Examples include Magento 2 Quick Flush Cache and Auto Flush Cache Module.

 

What should I do if my website crashes after finishing the cache?

You can troubleshoot through the following steps:

  • Try flushing again.
  • Check your server logs for error messages.
  • Determine whether any third-party extensions may be interfering.
  • Check to see if you've recently made configuration changes to the cache.

 

Key Points

Caching helps speed up the loading of pages on your e-commerce store. Studies show that page loading speed is a key customer satisfaction factor, and many customers will leave a site if the page loads too slowly. However, failure to flush the cache regularly also leads to a sluggish e-commerce site and can provide outdated information.

Regular cache management is critical to optimizing your e-commerce site. But you don't have to optimize your e-commerce store yourself. Partnering with a professional can enhance your site and give you more time to run your business. Contact the Transform Agency for custom solutions or to optimize your store's performance.

alex

Written with the assistance of Alex K.

Certified Magento Tech Lead at TA

Alex excels in creating and approving customization architecture, ensuring robust and efficient solutions for e-commerce platforms. His expertise in Magento allows him to effectively manage tech resources and drive technical projects to successful completion.

alex

Written with the assistance of Alex K.

Certified Magento Tech Lead at TA

Alex excels in creating and approving customization architecture, ensuring robust and efficient solutions for e-commerce platforms. His expertise in Magento allows him to effectively manage tech resources and drive technical projects to successful completion.

Previous How to Create a Configurable Product in Magento 2 Next How to Speed up Shopify Website [2024 Guide]
0 Comment(s)
To Top