Heres my problem:
I have multiple stores setup on my site.
www.xyz.com/us www.xyz.com/uk and so on...
Now each of these stores generates image cache that gets stored under media/catalogue as
media/catalog/product/cache/1 media/catalog/product/cache/2 media/catalog/product/cache/3
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.
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.
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
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:
Specifically in the public function setBaseFile($file) where it says:
// build new filename (most important params) $path = array( Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(), 'cache', Mage::app()->getStore()->getId(), $path = $this->getDestinationSubdir() );
We want it to be like this, but don’t edit this file!
// build new filename (most important params) $path = array( Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(), 'cache', 'all', $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 🙂
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0