Cache key length in asp.net

孤街浪徒 提交于 2019-12-23 12:23:19

问题


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?


回答1:


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?



来源:https://stackoverflow.com/questions/7530050/cache-key-length-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!