0

In a multi-store Magento build each store view will have a corresponding cache folder in /media/catalog/product/cache, e.g. '1' for store '1'.

In the website I am currently working on we have an ever-growing list of store views and I can't help but thinking I need to do something about the ever expanding list of cache image folders. The images are always the same regardless of the store view, so the extra cache folders really are duplicates. I would prefer just the one set of cached images, in part because this will make the product quicker and the bandwidth lower (a customer swapping a store view will not require an extra set of images to be loaded).

So far I have done little to 'fix' the per-store product image cache. I have also not found any other writing online about this 'problem' and how to fix it. Does anyone have any idea?

2
  • Can anyone please provide this same solution for magento2? Commented Jan 2, 2019 at 8:06
  • This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review Commented Jan 2, 2019 at 8:31

1 Answer 1

1

The cache file url, is build in the method Mage_Catalog_Model_Product_Image::setBaseFile, by this piece of code:

   $path = array(
        Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(),
        'cache',
        Mage::app()->getStore()->getId(),
        $path[] = $this->getDestinationSubdir()
    );

Later, the$path array is imploded into a string that becomes the path.
As you can see, the store id is part of the array.
You can rewrite this method and remove the line Mage::app()->getStore()->getId(),.
This should solve your problem and you will have the same cache for all store views.

3
  • Thankyou for that, oddly enough I found that I had already had the extended code with the store id commented out of the array! This was on a module from a previous project, but I had totally forgotten I knew how to do this. Thanks again! Commented Aug 4, 2015 at 14:30
  • I also needed to reindex, clear caches and those normal Magento things. Commented Aug 4, 2015 at 15:05
  • Any idea, how to achieve the same functionality on Magento 2?
    – CodeGenius
    Commented Aug 19, 2021 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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