In Sitecore Media Cache, the images are stored in MediaCache folder using a specific convention. This means if you need to locate an image in MediaCache folder, you need to understand this convention else you have to be really lucky to be able to find your image in MediaCache. I have many times figured this out earlier and then have also forgotten it when it was not needed. Recently, while working on a production issue, I again had to recall it to know if a media file is being served from MediaCache or not. So this time I decided to document it and share it with other developers in case they too struggle with it.
If you go to App_Data/MediaCache on your Sitecore instance, this is how a typical site folder in it looks like. All the media files for sites are cached in their site specific folders only -
If you go one level inside these folders, you will see this -
The above snapshot is from an example site which has few media items only. Your actual MediaCache folder may have hundreds of entries instead.
You will find there are typically two categories of files in these folders -
- INI file - These are basically configuration files.
- JPG, SVG, JS, CSS etc. - These are the media files cached on file system.
Typically, an INI file looks like below snapshot. The value against key represents a unique set of query parameters supplied in the media request and the value against dataFile is the file which will be served in response to the media request -
But the question is how to find the ini file related to you media file?
You might have observed that the ini file is named as a cleansed GUID. The GUID is actually the MediaID of the media item in media library. This MediaID is not same as the ID of the media item. In fact, the MediaID is a calculated value based on the below method -
You wont find the value for MediaID easily in Sitecore content editor or in Sitecore databases. Hence, I created a small PowerShell script to get the MediaID for media file -
$item = Get-Item -Path "master:/sitecore/media library/<path to your media file>"
$mediaItem = [Sitecore.Data.Items.MediaItem]::new($item)
$mediaData = [Sitecore.Resources.Media.MediaData]::new($mediaItem)
$mediaData.MediaId
This shall return you the MediaId of the media file as in snapshot below and then using that MediaId, you can search the related INI file in your App_Data/MediaCache folders.
Hope this helps you! Thanks for reading!!