Clear Magento cache

Clear Magento cache

July 2, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Clear Magento cache

Magento Cache Clearing: A Comprehensive Guide

Dear developers,

I recently received an inquiry from one of our valued readers about clearing the cache in Magento programmatically. This is a common question among Magento users, so I decided to write this post as a comprehensive guide.

Understanding Magento Caching

Magento uses various types of caching for performance optimization, including:

  1. Full Page Cache: Stores fully rendered pages.
  2. Block HTML Output Cache: Stores block-level output.
  3. Configuration Cache: Stores configuration settings.
  4. Layout XML Cache: Stores layout XML files.

These caches help reduce the load on your server by serving pre-rendered content to users.

Clearing Magento Cache Manually

Magento provides a built-in cache management interface in the admin panel:

  1. Log in to your Magento admin dashboard.
  2. Navigate to System > Cache Management.
  3. Select the cache types you want to flush, or click “Flush All Cache” for a complete clear.

Clearing Cache Programmatically: The Correct Way

The most common approach is to use the Mage::app()->getCache()->clean() method:

<?php
require_once('app/Mage.php');
umask(0);
Mage::app();

// Clear all cache types
Mage::app()->getCacheInstance()->clean();

However, you might face issues if your cache/clean directory is not properly set up or if there are cache type conflicts.

The Best Practice: Using the Command-Line Interface

Magento provides a command-line interface (CLI) for clearing the cache. This method is more reliable and easier to use:

  1. Open a terminal.
  2. Navigate to your Magento installation’s root directory using cd.
  3. Run the following command:
    php bin/magento cache:clean
    

This will clean all cache types.

If you want to flush only specific cache types, you can specify them like this:

php bin/magento cache:clean <cache_type>

For example, to clear only the block HTML output cache:

php bin/magento cache:clean config

Conclusion

Clearing Magento cache is a critical step in development and deployment processes. It ensures that your changes are reflected immediately.

Remember:

  • Use the CLI commands for a reliable clean.
  • Avoid using Mage::app()->getCache()->clean() due to potential conflicts.
  • Always test your configurations after clearing the cache.

For more advanced Magento optimizations, I recommend checking out our article on Magento performance optimization techniques.

Happy coding!

Cache Performance Themes Admin

Our network