Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.Net - ClientCache - can it vary by file type?

I've been taking a look, and implemented client caching on a development project I'm currently working on.

As I'm using Asp.Net, I've updated the web.config file directly with the following code:

<staticContent>
  <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
</staticContent>

I've also implemented a 'fingerprinting' solution which allows me to expire CSS and Script files from the cache automatically.

However, I got to thinking what if an image changes - lets say it's modified and re-uploaded without being renamed. In this scenario I don't necessarily want the browser to continue caching the old version of an image for up to a year.

The question is therefore can a different cache duration be set for different file types using the web.config static content section?

like image 306
John Ohara Avatar asked Apr 28 '15 16:04

John Ohara


People also ask

What is ClientCache?

A ClientCache instance controls the life cycle of the local singleton cache in a client.

Does IIS cache images?

IIS automatically caches static content (such as HTML pages, images, and style sheets), since these types of content do not change from request to request. IIS also detects changes to the files when you make updates, and IIS flushes the cache as needed.


1 Answers

You can use the location path to limit the cache to a folder or even down to a specific file. Not sure if you could do something like *.pdf. Possible option here: Can I use wildcards in the web.config location path attribute?

<location path="images">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
      </staticContent>
    </system.webServer>
  </location>
like image 69
Rick S Avatar answered Oct 02 '22 20:10

Rick S