Ways to clear the Magento cache

When design changes are made in Magento or when products in the catalog need to be updated, sometimes the changes do not appear in the front office of the website. This is because the Magento cache has not been cleared. How is it done? Below we provide the instructions to clear and disable the Magento cache.

A) CLEAR THE CACHE FROM THE BACKOFFICEClear the cache from the backoffice

  1. Open the Magento admin panel
  2. Click on the menu System>Cache Management
  3. Select all Cache types and in the Actions box choose refresh
  4. Click on Flush Magento Cache and Flush Cache Storage

B) KEEP THE CACHE DISABLED (recommended only if you are making changes to templates or any source file)

  1. On the same screen from step 2, select all Cache types and in the Actions box choose disable

Another way to clean the cache is to use the console ('shell' of Magento).

Directly from the console or 'terminal' (on Mac and Linux, in the case of Windows CMD would suffice, as long as we have the reference to the PHP libraries in the PATH), this code is executed from the same directory where we have the Magento installation:

First, we disable the default path, then we clear the cache, and finally we 'compile' again.

  1. php -f shell/compiler.php disable
  2. php -f shell/compiler.php clear
  3. php -f shell/compiler.php compile

If after performing all the previous steps you are unable to see the changes in your Magento store, you can try the following PHP script

Mage::setIsDeveloperMode(true);

if (!Mage::app()->isInstalled()) { echo "Application is not installed yet, please complete install wizard first."; exit(1); }

// Only for urls // Don't remove this $_SERVER['SCRIPT_FILENAME'] = 'index.php';

try { // CLEAN CACHE Mage::app()->cleanCache(); echo 'Cleared all caches' . "n";

// CATALOG REWRITES try { Mage::getSingleton('catalog/url')->refreshRewrites(); echo 'Catalog Rewrites were refreshed successfully' . "n"; } catch (Mage_Core_Exception $e) { echo $e->getMessage() . "n"; } catch (Exception $e) { echo 'Error while refreshed Catalog Rewrites. Please try again later' . "n"; }

// IMAGE CACHE try { Mage::getModel('catalog/product_image')->clearCache(); echo 'Image cache was cleared successfully' . "n"; } catch (Mage_Core_Exception $e) { echo $e->getMessage() . "n"; } catch (Exception $e) { echo 'Error while cleared Image cache. Please try again later' . "n"; }

// LAYERED NAV try { $flag = Mage::getModel('catalogindex/catalog_index_flag')->loadSelf(); if ($flag->getState() == Mage_CatalogIndex_Model_Catalog_Index_Flag::STATE_RUNNING) { $kill = Mage::getModel('catalogindex/catalog_index_kill_flag')->loadSelf(); $kill->setFlagData($flag->getFlagData())->save(); }

$flag->setState(Mage_CatalogIndex_Model_Catalog_Index_Flag::STATE_QUEUED)->save(); Mage::getSingleton('catalogindex/indexer')->plainReindex(); echo 'Layered Navigation Indices were refreshed successfully' . "n"; } catch (Mage_Core_Exception $e) { echo $e->getMessage() . "n"; } catch (Exception $e) { echo 'Error while refreshed Layered Navigation Indices. Please try again later' . "n"; }

// SEARCH INDEX try { Mage::getSingleton('catalogsearch/fulltext')->rebuildIndex(); echo 'Search Index was rebuilt successfully' . "n"; } catch (Mage_Core_Exception $e) { echo $e->getMessage() . "n"; } catch (Exception $e) { echo 'Error while rebuilt Search Index. Please try again later' . "n"; }

// STOCK STATUS try { Mage::getSingleton('cataloginventory/stock_status')->rebuild(); echo 'CatalogInventory Stock Status was rebuilt successfully' . "n"; } catch (Mage_Core_Exception $e) { echo $e->getMessage() . "n"; } catch (Exception $e) { echo 'Error while rebuilt CatalogInventory Stock Status. Please try again later' . "n"; }

// CLEAN CACHE Mage::app()->cleanCache(); echo 'Cleared all caches' . "n";

echo "n" . 'Cache clear complete!' . "n";

exit(0); } catch (Exception $e) { Mage::printException($e); }

exit(1);

Compartir:

🇬🇧 View in English?