asp.net - 在asp.net中缓存 key 长度

标签 asp.net caching outputcache

我正在调查 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/

相关文章:

c# - 将通配符与 LinqDataSource 一起使用

c# - 如何停止 web.config 继承

asp.net - 在带有母版页的网络表单中使用 dropzone.js

actionscript-3 - 缓存具有多个参数的方法结果的最佳方法 - 对象作为字典中的键?

java - 在spring cache中通过方法访问返回数据

asp.net - 在 ASP.NET 网页/WebMatrix 项目中启用输出缓存

asp.net-4.0 - 什么时候不应该在 Webforms 中设置 @OutputCache 共享属性?

javascript - 一段时间后加载网页 ASP.net 使用 Javascript

mysql - 每次用户访问页面时,DjangoCMS 都会打开数据库连接吗?

asp.net-mvc - Razor View 引擎 .cshtml 页面中的 OutputCache