我正在调查 MVC3 源代码并遇到以下内容(在 OutputCacheAttribute.cs 中),它在生成用于输出缓存的 key 时被调用:
// 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())));
}
评论说需要使用散列,因为“ key 通常太长而无用”。任何人都可以阐明这一点并推荐asp.net中缓存键的最大长度吗?
最佳答案
长度实际上并不重要,因为它被转换为哈希。
这适用于 MVC 和 ASP.NET。
Maximum length of cache keys in HttpRuntime.Cache object?
关于asp.net - 在asp.net中缓存 key 长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7530050/