Search code examples
sitecoresitecore-media-librarysitecore7.2

how many versions of caching can you have in sitecore


We have upgraded our Sitecore to 7.2 and we realize the size of Sitecore is growing. About 1/5 of the amount of space that is taken up is based in stored cache/binary code. For example when we update an image, Sitecore still stores the previous image in its memory which adds to the MB total. I am curious is there a way to clean out any previous media files when publishing or is there a setting in Sitecore that allows a certain amount of versions of stored files? I know in the right corner there is an arrow that stores previous versions of the entire file, that is not what I'm worried about I'm more worried about media storage or the binary memory.


Solution

  • Sitecore caches the media items to /App_Data/MediaCache for performance reasons and saves a trip back to the database. By default, any media over 90 days old gets deleted when the CleanupAgent is run:

    <agent type="Sitecore.Tasks.CleanupAgent" method="Run" interval="06:00:00">
      <!-- Specifies files to be cleaned up.
           If rolling="true", [minCount] and [maxCount] will be ignored.
           [minAge] and [maxAge] must be specified as [days.]hh:mm:ss. The default value
           of [minAge] is 30 minutes.
           [strategy]: number of files within hour, day, week, month, year
           [recursive=true|false]: descend folders?
      -->
      <files hint="raw:AddCommand">
        ...
        <remove folder="/App_Data/MediaCache" pattern="*.*" maxAge="90.00:00:00" recursive="true"/>
      </files>
    

    You could reduce the maxAge so something less to force it to clear up more often. Disk space is cheap though, but it obviously depends on the size of your media library. You should consider using a CDN to serve your media if it is very large.

    With regards to versioning, you can have an unlimited number of versions, although Sitecore recommends not keeping more than 10 versions per item.

    By default, Media Items are uploaded using the /sitecore/templates/System/Media/Unversioned templates, in which case the images are overwritten each time you upload a new image. If you use the Advanced Upload dialog and select the "versioned" option or set Media.UploadAsVersionableByDefault="true" in config then /sitecore/templates/System/Media/Versioned template will be used in which case you can you will end up with multiple versions. Check which template is being used and check your config if versions are not required.

    You could implement a rule to deleted old versions when an item is saved or implement a scheduled task to do the same. Also take a look at the Sitecore Version Pruner module but I suspect you do not want to serialize the files to disk since you end up back at the same issue of disk space.