Created
May 13, 2015 14:22
-
-
Save sihugh/020c160a6e02318aa934 to your computer and use it in GitHub Desktop.
A version of http://madskristensen.net/post/cache-busting-in-aspnet for when you can't easily mess with URL rewriting
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.Hosting; | |
using System.Web.Caching; | |
namespace Hughesdon.Cache { | |
public static class Fingerprint | |
{ | |
public static string Tag(string path) | |
{ | |
if(HttpRuntime.Cache[path] == null) | |
{ | |
string absolute = HostingEnvironment.MapPath("~" + path); | |
var lastModifiedDate = File.GetLastWriteTime(absolute); | |
string result = path + "?v=" + lastModifiedDate.Ticks; | |
HttpRuntime.Cache.Insert(path, result, new CacheDependency(absolute)); | |
} | |
return HttpRuntime.Cache[path] as string; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment