Umbraco 13 Image Sharp Cache Control Header Only Working Intermittently

On an Umbraco 13 site I help develop, we’re trying to set the Cache Control header for our ImageSharp images to one year. Our appsettings file is correctly configured, as specified here:

Here’s the relevant node in our appsettings file:

"Umbraco": {
  "CMS": {
    "Imaging": {
      "Cache": {
        "BrowserMaxAge": "365.00:00:00",
        "CacheMaxAge": "365.00:00:00"
      },
      "Resize": {
        "MaxWidth": 5000,
        "MaxHeight": 5000
      },
      "HMACSecretKey": ""
    }
	}
	}

What we’re finding is that, much of the time, the Cache Control header is what you’d expect/hope for (1 year). Sometimes, however, the Cache Control header is the default time of 7 days. That said, if I change the query string of the image in any way, for example, changing the order of the parameters, that seems to wake it up and the Cache Control header is correctly set to a year. I thought at first this might be some soft of caching issue, and I suppose it might be(?), but I did all my testing for this in incognito mode.

Any idea what could be causing this or if there’s a fix for this? Thanks.

Hi Jeremy :waving_hand:

I’d suspect that it’s only working for images that haven’t been requested before?

I don’t know how ImageSharp and/or Umbraco keeps track of them, but you could try clearing the ImageSharp cache completely (sorry, I don’t know how - they’re probably somewhere in the App_Data/TEMP folder) and see if that does the trick?

/Chriztian

I just read the linked docs article, and I can see that it states the default location for the cached images as umbraco/Data/Temp/MediaCache.

I wonder if the BrowserMaxAge that was originally used when creating the image is somehow stored or “baked” into the ?rnd parameter…

Deleting the image cache on Azure Blob Storage appears to have done the trick. Thanks!!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.