1

my media/catalog/product/cache directory is growing very hard.

Digging a bit deeper I see that every picture gets around 30 different files in my cache directory.

enter image description here In the picture you see the original file on top, and 30 different variants in the cache folder.

We have 80K+ products and adding a lot of products every season .... so my disk space is being filled very quickly.

Are there really 30 different image sizes needed? Or is there somewhere an option I may have set wrong?

we have Magento ver. 2.4.3-p2

1 Answer 1

2

There is a file vendor/magento/theme-frontend-luma/etc/view.xml that you may want to understand. This file will also be duplicated in your theme.

It has quite a lot of entries as you can see. Each setting will create a different file. Also, luma theme extends blank theme and I suspect the view.xml file from blank is also merged to this luma view file.

Overall, there are 30 image settings in these files. I made some experiments today.

  • clearing pub/media/catalog/product/cache folder
  • loading a category page with 1 product
  • visiting the product detail page
  • adding the product to the cart

What seems to happen is: the category page triggers the images for the product in the category to be generated for all these view settings. More accurately, the code \Magento\Catalog\Ui\DataProvider\Product\Listing\Collector\Image::collect is triggered when we load the category page

If you want to reduce the size of this folder, I suggest 2 things:

  1. If there is a setting you don't use, then change the view settings to be minimal in image size will mean the generated image in the cache folder will be smaller.. With your catalog, it will likely make a difference. This is a workaround rather than a solution of course
  2. The real solution would consist in removing some of these settings as it is likely you are not using them all. To do this, i have some ideas but they are yet to be implemented. the most straightforward would be to write an after plugin on the function \Magento\Framework\Config\View::getMediaAttributes to limit the settings to interact with.

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.