Created
March 17, 2014 15:17
-
-
Save rickj33/9601160 to your computer and use it in GitHub Desktop.
IIS Asset cache fingerprinting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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