Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan 1250 posts 3745 karma points admin c-trib
    1 week ago
    Dan
    0

    Reduce size of cached images

    Hi,

    I have a site running on Umbraco 7.5.11. It has <500Mb of images in total in the '/Media' folder on disk.

    However, the image cache (everything in App_Data/cache) exceeds 3Gb.

    The site doesn't do much in terms of resizing. There are a couple of templates which use images with e.g. ?width=1200 appended to their URLs but other than that, not much going on.

    I wondered:

    1. Why might the cache size be so large (and seemingly increasing)?
    2. What can be done to prevent the cache from growing so large. I wouldnt' have thought it would be much more than 1Gb considering it's only making some of the original images smaller in some places.

    The imageprocessor cache config is like this:

    <cache name="DiskCache" type="ImageProcessor.Web.Caching.DiskCache, ImageProcessor.Web" maxDays="365" browserMaxDays="7" trimCache="false">

    Would it help to set 'trimCache' to true?

    Thanks for any advice. :)

  • Marc Goodson 1178 posts 7892 karma points MVP 5x c-trib
    1 week ago
    Marc Goodson
    100

    Hi Dan

    Every time an image is requested with querystring parameters, then a cached version is created, and the cached version is used next time that image is requested, to prevent processing happening on every request.

    The backoffice also uses this for thumbnails etc.

    Overtime the cache can build up.

    The way trimCache setting works, is every time an image is saved, the rest of the cache is purged of old images. this prevents the cache continually increasing in size, but depending on the size of your media, can cause load on the server at inconvenient times... a commit was made here to turn trimCache off by default to avoid high CPU usage...

    https://github.com/umbraco/Umbraco-CMS/commit/389b29599b21876881e70599c12400b5053f7d13

    So an alternative is to manually delete your cache files every few months, next time an image is requested, it will be processed again, and a new cached version saved to disk. The cache will begin to grow again...

    ... if the size grows rapidly (it will to begin with as the majority of images are requested again for the first time) and continues to rise far above the size of the images in the media section, and you don't have any responsive image strategies that might be requesting different sizes on the fly, then another consideration is anything 'trolling' your site with requests to images with different combinations of parameters...? have a look in your IIS logs, to see if any images are being requested at unusual dimensions... from unusual IP addresses - if server disk space is a consideration, consider configuration the cache to be stored in Azure Blob storage or similar cloud location.

    regards

    Marc

  • Dan 1250 posts 3745 karma points admin c-trib
    1 week ago
    Dan
    0

    Thanks Marc. It doesn't sound like turning on trimCache would be wise. As you say, it might be that some kind of external bot/whatever might be "assisting" here by requesting images with querystring params. I did see some docs somewhere about locking this stuff down so I'll have a more detailed look into that. Thanks for your help.

Please Sign in or register to post replies

Write your reply to:

Draft