public void HashCombiner_Test_Int() { var combiner1 = new HashCodeCombiner(); combiner1.AddInt(1234); var combiner2 = new HashCodeCombiner(); combiner2.AddInt(1234); Assert.AreEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode()); combiner2.AddInt(1); Assert.AreNotEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode()); }
public override int GetHashCode () { HashCodeCombiner hashCodeCombiner = new HashCodeCombiner(); // We need non-randomized hash code for _varyByCustom hashCodeCombiner.AddInt(StringUtil.GetNonRandomizedHashCode(_varyByCustom)); hashCodeCombiner.AddArray(_varyByParams); hashCodeCombiner.AddArray(_varyByControls); return hashCodeCombiner.CombinedHash32; }
private string ComputeVaryCacheKey(HashCodeCombiner combinedHashCode, ControlCachedVary cachedVary) { // Add something to the has to differentiate it from the non-vary hash. // This is needed in case this method doesn't add anything else to the hash (VSWhidbey 194199) combinedHashCode.AddInt(1); // Get the request value collection NameValueCollection reqValCollection; HttpRequest request = Page.Request; if (request != null && request.HttpVerb == HttpVerb.POST) { // reqValCollection = new NameValueCollection(request.QueryString); reqValCollection.Add(request.Form); } else { // Use the existing value if possible to avoid recreating a NameValueCollection reqValCollection = Page.RequestValueCollection; // If it's not set, get it based on the method if (reqValCollection == null) { reqValCollection = Page.GetCollectionBasedOnMethod(true /*dontReturnNull*/); } } if (cachedVary._varyByParams != null) { ICollection itemsToUseForHashCode; // If '*' was specified, use all the items in the request collection. // Otherwise, use only those specified. if (cachedVary._varyByParams.Length == 1 && cachedVary._varyByParams[0] == "*") itemsToUseForHashCode = reqValCollection; else itemsToUseForHashCode = cachedVary._varyByParams; // Add the items and their values to compute the hash code foreach (string varyByParam in itemsToUseForHashCode) { // Note: we use to ignore certain system fields here (like VIEWSTATE), but decided // not to for consistency with pahe output caching (VSWhidbey 196267, 479252) combinedHashCode.AddCaseInsensitiveString(varyByParam); string val = reqValCollection[varyByParam]; if (val != null) combinedHashCode.AddObject(val); } } if (cachedVary._varyByControls != null) { // Prepend them with a prefix to make them fully qualified string prefix; if (NamingContainer == Page) { // No prefix if it's the page prefix = String.Empty; } else { prefix = NamingContainer.UniqueID; Debug.Assert(!String.IsNullOrEmpty(prefix)); prefix += IdSeparator; } prefix += _ctrlID + IdSeparator; // Add all the relative vary params and their values to the hash code foreach (string varyByParam in cachedVary._varyByControls) { string temp = prefix + varyByParam.Trim(); combinedHashCode.AddCaseInsensitiveString(temp); string val = reqValCollection[temp]; if (val != null) combinedHashCode.AddObject(reqValCollection[temp]); } } if (cachedVary._varyByCustom != null) { string customString = Context.ApplicationInstance.GetVaryByCustomString( Context, cachedVary._varyByCustom); if (customString != null) combinedHashCode.AddObject(customString); } return CacheInternal.PrefixPartialCachingControl + combinedHashCode.CombinedHashString; }
private string ComputeVaryCacheKey(HashCodeCombiner combinedHashCode, ControlCachedVary cachedVary) { combinedHashCode.AddInt(1); NameValueCollection requestValueCollection = this.Page.RequestValueCollection; if (requestValueCollection == null) { requestValueCollection = this.Page.GetCollectionBasedOnMethod(true); } if (cachedVary._varyByParams != null) { ICollection is2; if ((cachedVary._varyByParams.Length == 1) && (cachedVary._varyByParams[0] == "*")) { is2 = requestValueCollection; } else { is2 = cachedVary._varyByParams; } foreach (string str in is2) { combinedHashCode.AddCaseInsensitiveString(str); string s = requestValueCollection[str]; if (s != null) { combinedHashCode.AddObject(s); } } } if (cachedVary._varyByControls != null) { string str3; if (this.NamingContainer == this.Page) { str3 = string.Empty; } else { str3 = this.NamingContainer.UniqueID + base.IdSeparator; } str3 = str3 + this._ctrlID + base.IdSeparator; foreach (string str4 in cachedVary._varyByControls) { string str5 = str3 + str4.Trim(); combinedHashCode.AddCaseInsensitiveString(str5); if (requestValueCollection[str5] != null) { combinedHashCode.AddObject(requestValueCollection[str5]); } } } if (cachedVary._varyByCustom != null) { string varyByCustomString = this.Context.ApplicationInstance.GetVaryByCustomString(this.Context, cachedVary._varyByCustom); if (varyByCustomString != null) { combinedHashCode.AddObject(varyByCustomString); } } return ("l" + combinedHashCode.CombinedHashString); }