Skip to content

Instantly share code, notes, and snippets.

@wingsryder
Last active May 26, 2017 14:32
Show Gist options
  • Save wingsryder/0ee478711118630cc5002cd8f4977c60 to your computer and use it in GitHub Desktop.
Save wingsryder/0ee478711118630cc5002cd8f4977c60 to your computer and use it in GitHub Desktop.
Clean all magento cache including images and js/css
<?php
require 'app/Mage.php';
Mage::app('admin')->setUseSessionInUrl(false);
Mage::getConfig()->init();
echo "- Initializing cleaning all caches";
$types = Mage::app()->getCacheInstance()->getTypes();
try {
echo "- Refreshing data cache.\n";
flush();
foreach ($types as $type => $data) {
echo "---- Cleaning $type ... ";
echo Mage::app()->getCacheInstance()->clean($data["tags"]) ? "[DONE]" : "[ERROR]";
echo "\n";
}
} catch (exception $e) {
die("[ERROR:" . $e->getMessage() . "]");
}
try {
echo "\n- Cleaning stored cache.";
flush();
echo Mage::app()->getCacheInstance()->clean() ? "[DONE]" : "[ERROR]";
} catch (exception $e) {
die("\n[ERROR:" . $e->getMessage() . "]");
}
try {
echo "- Cleaning merged JS/CSS.";
flush();
Mage::getModel('core/design_package')->cleanMergedJsCss();
Mage::dispatchEvent('clean_media_cache_after');
echo "[DONE]\n\n";
} catch (Exception $e) {
die("[ERROR:" . $e->getMessage() . "]");
}
try {
echo "- Cleaning image cache.";
flush();
echo Mage::getModel('catalog/product_image')->clearCache();
echo "[OK]\n";
} catch (exception $e) {
die("[ERROR:" . $e->getMessage() . "]");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment