开发者

Cache key length in asp.net

开发者 https://www.devze.com 2023-04-08 11:34 出处:网络
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:

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消