A fingerprint class for versioning of static web content (derives from Mads Kristensen's Fingerprint class found here http://madskristensen.net/post/cache-busting-in-aspnet)
This file contains 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
using System.IO; | |
using System.Web; | |
using System.Web.Caching; | |
using System.Web.Hosting; | |
public static class Fingerprint | |
{ | |
public static string Tag(string rootRelativePath) | |
{ | |
if (null == HttpRuntime.Cache[rootRelativePath]) | |
{ | |
var absolute = HostingEnvironment.MapPath("~" + rootRelativePath); | |
var dateLastWrite = File.GetLastWriteTime(absolute); | |
var result = VirtualPathUtility.ToAbsolute( | |
string.Format("~{0}?{1}", | |
rootRelativePath, | |
dateLastWrite.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