14

I would like to manually clear the media cache on a production CD instance. Is there a way to clear the cache without causing disruption to the site?

14

It is completely safe to just delete the folder /App_data/MediaCache without causing disruption. The minute an image gets called up again, it will be cached again, so no worries about the functionality of your website. We make sure it get's cleaned up every week. In addition you can set up a clean up job to do the work for you. Unfortunately the usage of /sitecore/admin/cache.aspx does not clear the mediacache for you.

If you have an high performance on your website and 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" />

In addition, you can use an orchestration tool like puppet to periodically clean up your cache folder based on the timestamp of the files, this way, you don't have to worry about your cached items as they will be cleaned up automatically.

17

Other option is to delete from time to time media cache using an schedule agent. Current value is 24 days but if you need to clear more ofen just decrease max age parameter of the last setting (see below settings). It is not recommended to clear media cache very often because you will have some performance impact.

  <agent type="Sitecore.Tasks.CleanupAgent" method="Run" interval="01:00:00">
    <files hint="raw:AddCommand">
      <remove folder="$(dataFolder)/audit" pattern="audit.*.txt" maxCount="5" minAge="01:00:00" />
      <remove folder="$(dataFolder)/logs" pattern="log.*.txt" maxCount="5" minAge="01:00:00" />
      <remove folder="$(dataFolder)/viewstate" pattern="*.txt" maxAge="01:00:00" recursive="true" />
      <remove folder="/App_Data/MediaCache" pattern="*.*" maxAge="24.00:00:00" recursive="true" />
    </files>
  </agent> 
6

I have just manually deleted the folders under App_Data/MediaCache/[site name] on each CD server. Never seems to have caused disruption since Sitecore will fetch the image from the database again if it does not find a cached version.

1

It shouldn't be a problem deleting it however, the initial load time for each page will increase as it needs to fetch the media items fresh from the server.

Usually not a best practice to delete ~/App_Data/MediaCache on the production server during business hours. I would recommend lowering the maxAge in the clean up agent as mentioned above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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