1

When images are uploaded, they are resized and put into diffent cache folders. "pub/media/catalog/product/cache/1cd59219f95f9c415e6b76e445689a097/J/K/JK791735.jpg" ect..

Where in Magento is that current cache folder/hash stored? ("1cd59219f95f9c415e6b76e445689a097")

Is it calculated somehow? Stored i DB? Stored in a ini file somewhere?

2 Answers 2

0

The hash is computed in \Magento\Catalog\Model\View\Asset\Image::getMiscPath and is based on the following parameters:

image misc params in Magento 2

-1

The cache folder/hash for resized product images in Magento 2 is generated dynamically based on the image dimensions and aspect ratio, and it is stored in the cache_metadata table of the Magento database.

When an image is uploaded, Magento creates a unique identifier based on the image's size and aspect ratio, and uses that identifier to create the cache folder/hash in the pub/media/catalog/product/cache directory. The identifier is then stored in the cache_metadata table, along with the original image path and other metadata.

The cache_metadata table is used to map the cache folder/hash to the original image path, so that Magento can serve the cached image in place of the original image when the resized version is requested. This allows Magento to serve images quickly without having to resize them on-the-fly every time they are requested.

You can query the cache_metadata table to see the cache folder/hash values for your images. The SQL query would look something like this:

SELECT * FROM `cache_metadata` WHERE `media_type` = 'image' AND `metadata` LIKE '%/your/image/path.jpg';

This will return a row containing the cache folder/hash value for the specified image path.

2
  • 1
    Thank you for your answer. I cannot find any cache_metadata table? There is only a 'cache' table which is empty..
    – AP87
    Mar 23 at 6:56
  • Same here, cache_metadata doesn’t exist and is not mentioned in Magento’s source code.
    – bfontaine
    Jul 26 at 14:34

Your Answer

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

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