How to Enable or Disable Cache in Magento 2
In this article
To enable or disable the cache in Magento, navigate to the Admin Panel, go to System > Tools > Cache Management, and use the checkboxes to select specific cache types before clicking the Save or Flush buttons. For developers working via the command line, the bin/magento cache:enable and bin/magento cache:disable commands provide a faster way to manage these settings.
Understanding Magento's Caching Architecture
Magento is a complex enterprise platform that generates pages dynamically. Without caching, every single page load would require the server to query the database dozens of times and execute thousands of lines of PHP code, leading to unacceptable load times. Caching solves this by storing a "snapshot" of the processed data or the final HTML output in a high-speed storage area.
Magento utilizes several different layers of caching to optimize performance:
- Configuration Cache: Stores the merged configuration from all modules (system.xml, config.xml), preventing the system from reading these files on every request.
- Layout Cache: Stores the structure of the page (the XML layout instructions), so the system doesn't have to recalculate which blocks go where for every page.
- Block HTML Cache: Stores the actual HTML output of specific blocks (like the footer or navigation menu) that rarely change.
- Full Page Cache (FPC): The most powerful layer, which stores the entire HTML response for a URL, allowing the server to serve the page almost instantly without executing the full application logic.
Step-by-Step: Managing Cache via Admin Panel
The Admin Panel is the safest way for store managers to handle caching without needing SSH access to the server. Follow these steps to modify your cache settings:
- Log into your Magento Admin Dashboard.
- In the left-hand sidebar, navigate to System, then select Tools, and click on Cache Management.
- You will see a grid listing all available cache types. Use the checkboxes in the Enable column to toggle the status of each cache.
- If you have made changes to the site (such as updating a theme or adding a module) and the changes aren't appearing, select the relevant cache types and click the Flush Magento Cache button.
- Click Save to apply the enable/disable status changes.
Managing Cache via Command Line (CLI)
For developers and system administrators, the Command Line Interface (CLI) is the preferred method because it is faster and avoids the risk of being locked out of the Admin Panel if a cache issue causes a site crash.
To disable all caches, run the following command from the Magento root directory:
php bin/magento cache:disable
To enable all caches, use:
php bin/magento cache:enable
If you only need to target a specific cache, such as the layout cache, you can append the cache code to the command:
php bin/magento cache:clean layout
It is important to distinguish between cache:clean and cache:flush. Cleaning the cache removes only the items that Magento has tagged as belonging to that specific cache type. Flushing the cache clears the entire cache storage, including items that may have been placed there by other applications or extensions.
When to Enable vs. Disable Cache
Choosing whether to have the cache active depends entirely on your current environment. Using the wrong setting can either make your site unusable for customers or make your development process frustratingly slow.
Disable cache when:
- You are actively developing a new theme or modifying CSS/LESS files.
- You are debugging a PHP error or modifying a module's logic.
- You are testing changes to the system configuration in the Admin Panel that are not reflecting on the frontend.
Enable cache when:
- The site is in a production environment (Live).
- You are performing User Acceptance Testing (UAT) to see how the site performs under real-world conditions.
- You are running speed tests or optimizing Core Web Vitals.
Common Problems and Troubleshooting
One of the most common misconceptions in Magento is that disabling the cache is the only way to see changes. In reality, this can lead to a "development loop" where the site becomes so slow that it is difficult to test. Instead of disabling all caches, developers should identify which specific cache is blocking their changes.
If you have enabled the cache but still don't see your updates, consider these factors:
- Browser Caching: Your browser may be caching CSS or JS files. Try a hard refresh (Ctrl+F5) or use an Incognito window.
- Varnish Cache: If you are using Varnish as your Full Page Cache handler, flushing the Magento cache through the Admin Panel may not be enough. You may need to purge the Varnish cache separately via the server.
- OPcache: PHP's OPcache stores precompiled script bytecode in shared memory. If you change a PHP file and the change doesn't appear despite clearing Magento caches, you may need to restart the PHP-FPM service.
Frequently Asked Questions
Why is my site so slow after I disabled the cache?
Magento is designed to rely heavily on caching. When disabled, the server must regenerate every block and query the database for every single request. This increases the Time to First Byte (TTFB) significantly and is not sustainable for live traffic.
What is the difference between flushing and cleaning the cache?
Cleaning the cache removes only the entries that Magento manages. Flushing the cache clears the entire cache storage mechanism (like Redis or the file system), which may include data from other sources, making it a more aggressive operation.
Do I need to disable cache to change a product price?
Generally, no. Product updates usually trigger an automatic invalidation of the specific cache tags associated with that product. However, if you are using a third-party caching layer like Varnish or Cloudflare, you may need to purge those caches manually.
Can I disable only the Full Page Cache?
Yes. In the Cache Management section of the Admin Panel, you can uncheck only the "Full Page Cache" while keeping the Configuration and Layout caches enabled. This allows you to see page changes while maintaining some system performance.