Heres my problem:

I have multiple stores setup on my site.


www.xyz.com/uk  and so on...

Now each of these stores generates image cache that gets stored under media/catalogue as




The ID at the end are the store numbers.

Now whats happening is that the cache is the more or less the same across all the stores, and after a while it takes up too much space and I exceed my allotted disk space resulting with a 503 page.

What I need:

Would it be possible to have one centralised cache folder example : media/catalog/product/cache/1 where all the stores can create and refer cache to and from, that way the same image cache isn't created across different store caches.

Example -

www.xyz.com/us/123.jpg (store ID 1)

www.xyz.com/uk/123.jpg (store ID 2)

will create image caches in



For the same image.

Instead can it create image cache once in media/catalog/product/cache/1 where both stores can access the cached file.


CAUTION: only do this if you know the images represent the same thing, after this Magento is going to think it cached the image before and use it, so if you know your images are the same for every storeview, you can do this.

You can find the answer in the following file: ./app/code/core/Mage/Catalog/Model/Product/Image.php

Specifically in the public function setBaseFile($file) where it says:

// build new filename (most important params)
$path = array(
    $path[] = $this->getDestinationSubdir()

We want it to be like this, but don't edit this file!

// build new filename (most important params)
$path = array(
    $path[] = $this->getDestinationSubdir()

This will save every image to cache/all instead of cache/1, cache/2, cache/3 etc. but please read the caution :)

Now, to apply this, there are good ways and bad ways. Baddest is to edit the core file, so don't!

A little better, but still not ideal is to copy the file to ./app/code/local/Mage/Catalog/Model/Product/Image.php and make the change. That, however, would leave you with a little more work when upgrading Magento to a newer version, as this file will not be upgraded with it and you will run into problems eventually.

The Magento way is to create a little extension for this that rewrites the class to your own, then in your class you would extend the class Mage_Catalog_Model_Product_Image, only copy the setBaseFile-function and make the change there.

A nice tool to quickly generate a skeleton extension (and specify your rewrite in this case) is http://www.silksoftware.com/magento-module-creator/

Hope this helps :)

| improve this answer | |
  • All the stores use the same images. However there are one or two stores that have products/images that are not there in the other stores. Will this cause a problem? – user2240778 Dec 7 '14 at 4:58
  • If those images have different filenames there shouldn't be a problem. I always try to put the SKU in the filename so the images are always unique. – Marco de Vries Dec 7 '14 at 12:00
  • If this helped you please mark as answered so that others with the same question find the answer as well. – Marco de Vries Dec 8 '14 at 21:07
  • I tried creating a custom module as you outlined. under code/local/xxx/xxx/Model/Catalog/Product/Image/image.php I put <?php class Koshmart_Imagecache_Model_Catalog_Product_Image extends Mage_Catalog_Model_Product_Image { public function setBaseFile($file) { // build new filename (most important params) $path = array( Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(), 'cache', 'all', //Mage::app()->getStore()->getId(), $path[] = $this->getDestinationSubdir() ); } } – user2240778 Dec 19 '14 at 2:29
  • And under app/etc/modules <config> <modules> <XXX_Imagecache> <active>true</active> <codePool>local</codePool> <version>0.1.0</version> </XXX_Imagecache> </modules> </config> And it doesn't work. However if I delete this XML file then it works in the standard way. Something I'm doing wrong? – user2240778 Dec 19 '14 at 2:33

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.