public static string GetHash(string name)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentNullException("name", "name must contain a value.");
}
string key = string.Concat("BlueCollar.Dashboard.StaticFileHandler.Hash.", name).ToUpperInvariant();
string hash = HttpRuntime.Cache[key] as string;
if (string.IsNullOrEmpty(hash))
{
StringBuilder hex = new StringBuilder();
byte[] buffer;
using (MD5 hasher = MD5.Create())
{
buffer = hasher.ComputeHash(GetContents(name));
}
foreach (byte b in buffer)
{
hex.Append(b.ToString("X2", CultureInfo.InvariantCulture));
}
hash = hex.ToString().ToLowerInvariant();
HttpRuntime.Cache.Add(
key,
hash,
null,
Cache.NoAbsoluteExpiration,
Cache.NoSlidingExpiration,
CacheItemPriority.Normal,
null);
}
return hash;
}