public static string VersionedContent(this UrlHelper helper, string contentPath) { var fullPath = helper.RequestContext.HttpContext.Server.MapPath(contentPath); var version = AssetVersionCache.GetOrAddCachedVersion(fullPath, helper.RequestContext.HttpContext.Cache); if (version != null) { var relativePath = helper.Content(contentPath); // append hash to query string return(AppendVersion(relativePath, version)); } return(helper.Content(contentPath)); }
public static string GetOrAddCachedVersion(string filePath, Cache cache) { if (!File.Exists(filePath)) { return(null); } var assetCache = GetOrCreateAssetCache(cache); var version = string.Empty; if (assetCache.ContainsKey(filePath)) { version = assetCache[filePath]; } else { version = AssetVersionCache.ComputeHash(filePath); version = assetCache.GetOrAdd(filePath, version); } return(version); }