The file time stamp is automatically checked in IIS and the browser always requests the server for updated file based on the timestamp, so the .nocache. files don't need anything special in IIS.
However if you wanted the browser to cache the .cache. files then the following HttpModule sets the cache expiration date to 30 days from now for files that end in .cache.js or .cache.html (or any extension). The browser won't even request for updated versions of these files.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace CacheModulePlayground
{
public class CacheModule : IHttpModule
{
private HttpApplication _context;
public void Init(HttpApplication context)
{
_context = context;
context.PreSendRequestHeaders += context_PreSendRequestHeaders;
}
void context_PreSendRequestHeaders(object sender, EventArgs e)
{
if (_context.Response.StatusCode == 200 || _context.Response.StatusCode == 304)
{
var path = _context.Request.Path;
var dotPos = path.LastIndexOf('.');
if (dotPos > 5)
{
var preExt = path.Substring(dotPos - 6, 7);
if (preExt == ".cache.")
{
_context.Response.Cache.SetExpires(DateTime.UtcNow.Add(TimeSpan.FromDays(30)));
}
}
}
}
public void Dispose()
{
_context = null;
}
}
}
The web.config for this is:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<modules>
<add name="cacheExtension" type="CacheModulePlayground.CacheModule"/>
</modules>
</system.webServer>
</configuration>