1

We are using Versioned Media Items on our website. Our media URLs will be in the format -

https://domain/-/media path.pdf?sc_lang=en&hash=6952A5CAEA1FC60BEF7CCDF29B0293E2

After we attach a pdf file in the latest version and publish,media url in the front end website remains same (https://domain/-/media path.pdf?sc_lang=en&hash=6952A5CAEA1FC60BEF7CCDF29B0293E2) and also we are able to view only the old pdf file but not the latest one.

We checked the Web DB and latest published file is available there. Only after manually clearing cache we are able to view the latest file. Is any fix available for getting latest versioned file on front end site after publishing without the need of manual cache clear?

1
  • did you try updating the Media.AlwaysAppendRevision value to true in configuration? KB Article is very old and setting MediaResponse.MaxAge to 1 second is not a good idea because of performance. Aug 25, 2022 at 13:03

2 Answers 2

0

This happens because the media is cached in the browser for the time specified in the MediaResponse.MaxAge setting. If a browser has already accessed the media item, it may not perform any requests to the server and may retrieve the media item from its cache until the cached version expires.

To force the browser to always check whether the media item has changed since the last request, and download a new version if necessary, you need to set the MediaResponse.MaxAge setting in the Sitecore.config file to 00:00:01. This makes Sitecore set Cache-Control: max-age and Expires headers of the HTTP response for media requests to 1 second.

<!--  MEDIA RESPONSE - MAX AGE
            The <see cref="HttpCachePolicy.SetMaxAge">max age</see> to use in media response headers.
            Set it to "00:00:00" to omit this header.
            Default value: 7.00:00:00 (seven days)
      -->
    <setting name="MediaResponse.MaxAge" value="00:00:01" />

For more details refer to this KB article: https://support.sitecore.com/kb?id=kb_article_view&sysparm_article=KB0218124

0

If you do not want to cache your media items at all, you can always set this up in the sitecore.config file.

<!--  MEDIA - CACHE FOLDER
        The folder under which media files are cached by the system.
        Default value: /App_Data/MediaCache
  -->
<setting name="Media.CacheFolder" value="/App_Data/MediaCache" />
<!--  MEDIA - CACHING ENABLED
        Indicates if caching of media files is enabled.
        Default value: true
  -->
<setting name="Media.CachingEnabled" value="false" />

There is a Media.AlwaysAppendRevision setting in Sitecore.config. If the setting set to true then Sitecore appends media item revision number to the media URLs generated by LinkManager.

<setting name="Media.AlwaysAppendRevision" value="true" />

Try this and it should resolve your issue.

Thanks

2
  • Thanks for the answer but Media Cache was already disabled
    – Sylesh JL
    Aug 25, 2022 at 10:57
  • @SyleshJL Updated my answer. Please check this. Aug 25, 2022 at 11:16

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.