Cache key length in asp.net
I was investigating the MVC3 source and came across the following (in OutputCacheAttribute.cs) which is called when generating a key to use for output caching:
// The key is typically too long to be useful, so we use a cryptographic hash
// as the actual key (better randomization and key distribution, so small vary
开发者_开发百科 // values will generate dramtically different keys).
using (SHA256 sha = SHA256.Create()) {
return Convert.ToBase64String(sha.ComputeHash(Encoding.UTF8.GetBytes(uniqueIdBuilder.ToString())));
}
The comment says that the use of a hash is required because "The key is typically too long to be useful". Can anyone shed light on this and recommend a maximum length for cache keys in asp.net?
The length doesn't actually matter as it is converted to a hash. This applies to MVC and ASP.NET.
Maximum length of cache keys in HttpRuntime.Cache object?
精彩评论