On Magento 1.x I can clean all products image cache using:


and I can clean a single product data cache using:

Mage::app()->cleanCache('CATALOG_PRODUCT_' . $the_product_id);

But does it exists a command to clean the image cache of a single product?

3 Answers 3


No, there is no command to do that.

Reason : Catalog image cache is created as per size requirements. If you create a template from which you call images for 100 * 100 size, you'll get a new image cache location for all the product images in that size. If you want to delete cached images for a single product, you'll need to locate all the calls to product image in every template file and then work your way through that. That is pretty much insane and also, just an edit in the template would leave that method useless.

When you delete entire image cache, all Magento does is recursively delete everything inside /media/catalog/product/cache/ folder.

  • that solved my problem as we had a 2.8 GB cache .. thanks (: Apr 1, 2018 at 7:22

If this is on a Linux server, one way to do it is to find all items under media/catalog/product/cache last accessed older than xxx days and delete. Run it periodically to clean out old cached images. Magento will recreate anything that still exists in the product images store.

Something like the following ($DOCDIR is path to your http doc root):

find $DOCDIR/media/catalog/product/cache/* -type f -atime +365 -exec rm -f {} \;

While this isn't Magento programmatic (since Magento doesn't do certain important housecleaning EVER and therefore doesn't have any built-in mechanism) it could be worked into some sort of adjunct module to compliment the next item below which you will need to do some of the above disk eating missing housecleaning.

Also, there's a free module Image Clean that will delete the unused original images that are left behind when you delete product from your catalog.


For cleaning cache you need to use this code :

$directory = Mage::getBaseDir('media').DS.'catalog'.DS.'product'.DS.'cache'.DS;

$io = new Varien_Io_File();

$io->rmdir($directory, true);


Note: If you want to remove single product set the directory path to that product image.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.