To ensure that new images are served, and not old ones from cache, you "cache bust" the images to include a revision parameter.
Create a new class, inheriting from the old one and append the revision or the modified date:
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Resources.Media;
namespace MyProject.CMS.Custom.Media
{
public class MediaProvider: Sitecore.Resources.Media.MediaProvider
{
public override string GetMediaUrl(MediaItem item)
{
Assert.ArgumentNotNull((object)item, "item");
return this.GetMediaUrl(item, MediaUrlOptions.Empty);
}
public override string GetMediaUrl(MediaItem item, MediaUrlOptions options)
{
Assert.ArgumentNotNull((object) item, "item");
Assert.ArgumentNotNull((object) options, "options");
string mediaURL = base.GetMediaUrl(item, options);
mediaURL = Sitecore.Web.WebUtil.AddQueryString(mediaURL, new string[] {"revision", ((Item)item).Statistics.Revision });
//OR
mediaURL = Sitecore.Web.WebUtil.AddQueryString(mediaURL, new string[] {"modified", ((Item)item).Statistics.Updated.ToString("yyyyMMddHHmmss") });
return mediaURL;
}
}
}
Update the config to point to your new class.
<mediaLibrary>
<mediaProvider>
<patch:attribute name="type">MyProject.CMS.Custom.Media.MediaProvider, MyProject.CMS.Custom</patch:attribute>
</mediaProvider>
</mediaLibrary>
As @Gatogordo mentions in his answer, you should leave DisableBrowserCaching=true
especially if you have dynamic pages which should always be served from the server. Make sure you have the cache settings configured on the controls in Sitecore so server side caching is optimal.
The MediaResponse.Cacheability
will depend on whether you are using any content delivery networks, but generally public
is a fairly safe configuration for optimal caching downstream. Combined with the code above, any updates to media should be reflected to the user without any issues.