Skip to content

Instantly share code, notes, and snippets.

@rickj33
Created March 17, 2014 15:17
Show Gist options
  • Save rickj33/9601160 to your computer and use it in GitHub Desktop.
Save rickj33/9601160 to your computer and use it in GitHub Desktop.
IIS Asset cache fingerprinting.
//source-reference http://madskristensen.net/post/cache-busting-in-aspnet
using System;
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Web.Hosting;
public class Fingerprint
{
public static string Tag(string rootRelativePath)
{
if (HttpRuntime.Cache[rootRelativePath] == null)
{
string absolute = HostingEnvironment.MapPath("~" + rootRelativePath);
DateTime date = File.GetLastWriteTime(absolute);
int index = rootRelativePath.LastIndexOf('/');
string result = rootRelativePath.Insert(index, "/v-" + date.Ticks);
HttpRuntime.Cache.Insert(rootRelativePath, result, new CacheDependency(absolute));
}
return HttpRuntime.Cache[rootRelativePath] as string;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment