public override bool Equals(object obj)
        {
            if (!(obj is ControlCachedVary))
            {
                return(false);
            }
            ControlCachedVary vary = (ControlCachedVary)obj;

            return(((this._varyByCustom == vary._varyByCustom) && StringUtil.StringArrayEquals(this._varyByParams, vary._varyByParams)) && StringUtil.StringArrayEquals(this._varyByControls, vary._varyByControls));
        }
Exemplo n.º 2
0
        public override bool Equals(Object obj)
        {
            if (!(obj is ControlCachedVary))
            {
                return(false);
            }

            ControlCachedVary cv = (ControlCachedVary)obj;

            return(_varyByCustom == cv._varyByCustom &&
                   StringUtil.StringArrayEquals(_varyByParams, cv._varyByParams) &&
                   StringUtil.StringArrayEquals(_varyByControls, cv._varyByControls));
        }
Exemplo n.º 3
0
        internal override void InitRecursive(Control namingContainer)
        {
            HashCodeCombiner combinedHashCode = new HashCodeCombiner();

            _cacheKey = ComputeNonVaryCacheKey(combinedHashCode);

            // Save the non-varying hash, so we don't need to recalculate it later
            _nonVaryHashCode = combinedHashCode.CombinedHash;

            PartialCachingCacheEntry cacheEntry = null;

            // Check if there is a cache entry for the non-varying key
            object tmpCacheEntry = OutputCache.GetFragment(_cacheKey, _provider);

            if (tmpCacheEntry != null)
            {
                ControlCachedVary cachedVary = tmpCacheEntry as ControlCachedVary;
                if (cachedVary != null)
                {
                    string varyCachedKey = ComputeVaryCacheKey(combinedHashCode, cachedVary);

                    // Check if there is a cache entry for the varying key
                    cacheEntry = (PartialCachingCacheEntry)OutputCache.GetFragment(varyCachedKey, _provider);
                    if (cacheEntry != null && cacheEntry._cachedVaryId != cachedVary.CachedVaryId)
                    {
                        cacheEntry = null;
                        // explicitly remove the entry
                        OutputCache.RemoveFragment(varyCachedKey, _provider);
                    }
                }
                else
                {
                    // If it wasn't a ControlCachedVary, it must be a PartialCachingCacheEntry
                    cacheEntry = (PartialCachingCacheEntry)tmpCacheEntry;
                }
            }

            // If it's a cache miss, create the control and make it our child
            if (cacheEntry == null)
            {
                // Cache miss

                _cacheEntry = new PartialCachingCacheEntry();

                _cachedCtrl = CreateCachedControl();
                Controls.Add(_cachedCtrl);

                // Make sure the Page knows about us while the control's OnInit is called
                Page.PushCachingControl(this);
                base.InitRecursive(namingContainer);
                Page.PopCachingControl();
            }
            else
            {
                // Cache hit

                _outputString   = cacheEntry.OutputString;
                _cssStyleString = cacheEntry.CssStyleString;

                // If any calls to Register* API's were made when the control was run,
                // make them now to restore correct behavior (VSWhidbey 80907)
                if (cacheEntry.RegisteredClientCalls != null)
                {
                    foreach (RegisterCallData registerCallData in cacheEntry.RegisteredClientCalls)
                    {
                        switch (registerCallData.Type)
                        {
                        case ClientAPIRegisterType.WebFormsScript:
                            Page.RegisterWebFormsScript();
                            break;

                        case ClientAPIRegisterType.PostBackScript:
                            Page.RegisterPostBackScript();
                            break;

                        case ClientAPIRegisterType.FocusScript:
                            Page.RegisterFocusScript();
                            break;

                        case ClientAPIRegisterType.ClientScriptBlocks:
                        case ClientAPIRegisterType.ClientScriptBlocksWithoutTags:
                        case ClientAPIRegisterType.ClientStartupScripts:
                        case ClientAPIRegisterType.ClientStartupScriptsWithoutTags:
                            Page.ClientScript.RegisterScriptBlock(registerCallData.Key,
                                                                  registerCallData.StringParam2, registerCallData.Type);
                            break;

                        case ClientAPIRegisterType.OnSubmitStatement:
                            Page.ClientScript.RegisterOnSubmitStatementInternal(registerCallData.Key,
                                                                                registerCallData.StringParam2);
                            break;

                        case ClientAPIRegisterType.ArrayDeclaration:
                            Page.ClientScript.RegisterArrayDeclaration(registerCallData.StringParam1,
                                                                       registerCallData.StringParam2);
                            break;

                        case ClientAPIRegisterType.HiddenField:
                            Page.ClientScript.RegisterHiddenField(registerCallData.StringParam1,
                                                                  registerCallData.StringParam2);
                            break;

                        case ClientAPIRegisterType.ExpandoAttribute:
                            Page.ClientScript.RegisterExpandoAttribute(registerCallData.StringParam1,
                                                                       registerCallData.StringParam2, registerCallData.StringParam3, false);
                            break;

                        case ClientAPIRegisterType.EventValidation:
                            if (_registeredCallDataForEventValidation == null)
                            {
                                _registeredCallDataForEventValidation = new ArrayList();
                            }

                            _registeredCallDataForEventValidation.Add(registerCallData);
                            break;

                        default:
                            Debug.Assert(false);
                            break;
                        }
                    }
                }

                base.InitRecursive(namingContainer);
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        /// <internalonly/>
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected internal override void Render(HtmlTextWriter output)
        {
            CacheDependency sqlCacheDep = null;

            // If the output is cached, use it and do nothing else
            if (_outputString != null)
            {
                output.Write(_outputString);
                RegisterValidationEvents();
                return;
            }

            // If caching was turned off, just render the control
            if (_cachingDisabled || !RuntimeConfig.GetAppConfig().OutputCache.EnableFragmentCache)
            {
                _cachedCtrl.RenderControl(output);
                return;
            }

            // Create SQL cache dependency before we render the page
            if (_sqlDependency != null)
            {
                sqlCacheDep = SqlCacheDependency.CreateOutputCacheDependency(_sqlDependency);
            }

            _cacheEntry.CssStyleString = GetCssStyleRenderString(output.GetType());

            // Create a new HtmlTextWriter, with the same type as the current one (see ASURT 118922)
            StringWriter    tmpWriter     = new StringWriter();
            HtmlTextWriter  tmpHtmlWriter = Page.CreateHtmlTextWriterFromType(tmpWriter, output.GetType());
            CacheDependency cacheDep;
            TextWriter      savedWriter = Context.Response.SwitchWriter(tmpWriter);

            try {
                // Make sure the Page knows about us while the control's OnPreRender is called
                Page.PushCachingControl(this);
                _cachedCtrl.RenderControl(tmpHtmlWriter);
                Page.PopCachingControl();
            }
            finally {
                Context.Response.SwitchWriter(savedWriter);
            }

            _cacheEntry.OutputString = tmpWriter.ToString();

            // Send the output to the response
            output.Write(_cacheEntry.OutputString);

            // Cache the output

            cacheDep = _cacheDependency;

            if (sqlCacheDep != null)
            {
                if (cacheDep == null)
                {
                    cacheDep = sqlCacheDep;
                }
                else
                {
                    AggregateCacheDependency aggr = new AggregateCacheDependency();

                    aggr.Add(cacheDep);
                    aggr.Add(sqlCacheDep);
                    cacheDep = aggr;
                }
            }

            ControlCachedVary cachedVary = null;
            string            realItemCacheKey;

            // If there are no varies, use the non-varying key
            if (_varyByParamsCollection == null && _varyByControlsCollection == null && _varyByCustom == null)
            {
                realItemCacheKey = _cacheKey;
            }
            else
            {
                string[] varyByParams = null;
                if (_varyByParamsCollection != null)
                {
                    varyByParams = _varyByParamsCollection.GetParams();
                }

                cachedVary = new ControlCachedVary(varyByParams, _varyByControlsCollection, _varyByCustom);

                HashCodeCombiner combinedHashCode = new HashCodeCombiner(_nonVaryHashCode);
                realItemCacheKey = ComputeVaryCacheKey(combinedHashCode, cachedVary);
            }

            // Compute the correct expiration, sliding or absolute
            DateTime utcExpirationTime;
            TimeSpan slidingExpiration;

            if (_useSlidingExpiration)
            {
                utcExpirationTime = Cache.NoAbsoluteExpiration;
                slidingExpiration = _utcExpirationTime - DateTime.UtcNow;
            }
            else
            {
                utcExpirationTime = _utcExpirationTime;
                slidingExpiration = Cache.NoSlidingExpiration;
            }

            try {
                OutputCache.InsertFragment(_cacheKey, cachedVary,
                                           realItemCacheKey, _cacheEntry,
                                           cacheDep /*dependencies*/,
                                           utcExpirationTime, slidingExpiration,
                                           _provider);
            }
            catch {
                if (cacheDep != null)
                {
                    cacheDep.Dispose();
                }
                throw;
            }
        }
Exemplo n.º 6
0
        // insert fragment
        internal static void InsertFragment(String cachedVaryKey, ControlCachedVary cachedVary,
                                            String fragmentKey, PartialCachingCacheEntry fragment,
                                            CacheDependency dependencies,
                                            DateTime absExp, TimeSpan slidingExp,
                                            String providerName) {

            // if providerName is not null, find the provider in the collection.
            // if providerName is null, use default provider.
            // if the default provider is undefined or the fragment can't be inserted in the
            // provider, insert it in the internal cache.
            OutputCacheProvider provider = GetFragmentProvider(providerName);

            //
            // ControlCachedVary and PartialCachingCacheEntry can be serialized
            //

            bool useProvider = (provider != null);
            if (useProvider) {
                bool canUseProvider = (slidingExp == Cache.NoSlidingExpiration
                                       && (dependencies == null || dependencies.IsFileDependency()));
            
                if (useProvider && !canUseProvider) {
                    throw new ProviderException(SR.GetString(SR.Provider_does_not_support_policy_for_fragments, providerName));
                }
            }

#if DBG
            bool cachedVaryPutInCache = (cachedVary != null);
#endif
            if (cachedVary != null) {
                // Add the ControlCachedVary item so that a request will know
                // which varies are needed to issue another request.

                // Use the Add method so that we guarantee we only use
                // a single ControlCachedVary and don't overwrite existing ones.
                ControlCachedVary cachedVaryInCache;
                if (!useProvider) {
                    cachedVaryInCache = OutputCache.UtcAdd(cachedVaryKey, cachedVary);
                }
                else {
                    cachedVaryInCache = (ControlCachedVary) provider.Add(cachedVaryKey, cachedVary, Cache.NoAbsoluteExpiration);
                }
                
                if (cachedVaryInCache != null) {
                    if (!cachedVary.Equals(cachedVaryInCache)) {
                        // overwrite existing cached vary
                        if (!useProvider) {
                            HttpRuntime.CacheInternal.UtcInsert(cachedVaryKey, cachedVary);
                        }
                        else {
                            provider.Set(cachedVaryKey, cachedVary, Cache.NoAbsoluteExpiration);
                        }
                    }
                    else {
                        cachedVary = cachedVaryInCache;
#if DBG
                        cachedVaryPutInCache = false;
#endif
                    }
                }

                if (!useProvider) {
                    AddCacheKeyToDependencies(ref dependencies, cachedVaryKey);
                }

                // not all caches support cache key dependencies, but we can use a "change number" to associate
                // the ControlCachedVary and the PartialCachingCacheEntry
                fragment._cachedVaryId = cachedVary.CachedVaryId;
            }

            // Now insert into the cache (use cache provider if possible, otherwise use internal cache)
            if (!useProvider) {
                HttpRuntime.CacheInternal.UtcInsert(fragmentKey, fragment,
                                                    dependencies,
                                                    absExp, slidingExp,
                                                    CacheItemPriority.Normal,
                                                    null);
            }
            else {
                string depKey = null;
                if (dependencies != null) {
                    depKey = OUTPUTCACHE_KEYPREFIX_DEPENDENCIES + dependencies.GetUniqueID();
                    fragment._dependenciesKey = depKey;
                    fragment._dependencies = dependencies.GetFileDependencies();
                }                
                provider.Set(fragmentKey, fragment, absExp);
                if (dependencies != null) {
                    // use Add and dispose dependencies if there's already one in the cache
                    Object d = HttpRuntime.CacheInternal.UtcAdd(depKey, new DependencyCacheEntry(fragmentKey, null, provider.Name),
                                                                dependencies,
                                                                absExp, Cache.NoSlidingExpiration,
                                                                CacheItemPriority.Normal, s_dependencyRemovedCallbackForFragment);
                    if (d != null) {
                        dependencies.Dispose();
                    }
                }
            }

#if DBG
            string cachedVaryType = (cachedVaryPutInCache) ? "ControlCachedVary" : "";
            string providerUsed = (useProvider) ? provider.Name : "CacheInternal";
            Debug.Trace("OutputCache", "InsertFragment(" 
                        + cachedVaryKey + ", " 
                        + cachedVaryType + ", " 
                        + fragmentKey + ", PartialCachingCacheEntry, ...) -->"
                        + providerUsed);
#endif
        }
Exemplo n.º 7
0
 // add ControlCachedVary
 private static ControlCachedVary UtcAdd(String key, ControlCachedVary cachedVary) {
     return (ControlCachedVary) HttpRuntime.CacheInternal.UtcAdd(key, 
                                                          cachedVary, 
                                                          null /*dependencies*/, 
                                                          Cache.NoAbsoluteExpiration, 
                                                          Cache.NoSlidingExpiration, 
                                                          CacheItemPriority.Normal, 
                                                          null /*callback*/);
 }        
Exemplo n.º 8
0
    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;
    }
Exemplo n.º 9
0
    /// <internalonly/>
    /// <devdoc>
    ///    <para>[To be supplied.]</para>
    /// </devdoc>
    protected internal override void Render(HtmlTextWriter output) {
        CacheDependency sqlCacheDep = null;

        // If the output is cached, use it and do nothing else
        if (_outputString != null) {
            output.Write(_outputString);
            RegisterValidationEvents();
            return;
        }

        // If caching was turned off, just render the control
        if (_cachingDisabled || !RuntimeConfig.GetAppConfig().OutputCache.EnableFragmentCache) {
            _cachedCtrl.RenderControl(output);
            return;
        }

        // Create SQL cache dependency before we render the page
        if (_sqlDependency != null) {
            sqlCacheDep = SqlCacheDependency.CreateOutputCacheDependency(_sqlDependency);
        }

        _cacheEntry.CssStyleString = GetCssStyleRenderString(output.GetType());

        // Create a new HtmlTextWriter, with the same type as the current one (see ASURT 118922)
        StringWriter tmpWriter = new StringWriter();
        HtmlTextWriter tmpHtmlWriter = Page.CreateHtmlTextWriterFromType(tmpWriter, output.GetType());
        CacheDependency cacheDep;
        TextWriter savedWriter = Context.Response.SwitchWriter(tmpWriter);

        try {
            // Make sure the Page knows about us while the control's OnPreRender is called
            Page.PushCachingControl(this);
            _cachedCtrl.RenderControl(tmpHtmlWriter);
            Page.PopCachingControl();
        }
        finally {
            Context.Response.SwitchWriter(savedWriter);
        }

        _cacheEntry.OutputString = tmpWriter.ToString();

        // Send the output to the response
        output.Write(_cacheEntry.OutputString);

        // Cache the output

        cacheDep = _cacheDependency;

        if (sqlCacheDep != null) {
            if (cacheDep == null) {
                cacheDep = sqlCacheDep;
            }
            else {
                AggregateCacheDependency aggr = new AggregateCacheDependency();

                aggr.Add(cacheDep);
                aggr.Add(sqlCacheDep);
                cacheDep = aggr;
            }
        }

        ControlCachedVary cachedVary = null;
        string realItemCacheKey;
        // If there are no varies, use the non-varying key
        if (_varyByParamsCollection == null && _varyByControlsCollection == null && _varyByCustom == null) {
            realItemCacheKey = _cacheKey;
        }
        else {
            string[] varyByParams = null;
            if (_varyByParamsCollection != null)
                varyByParams = _varyByParamsCollection.GetParams();

            cachedVary = new ControlCachedVary(varyByParams, _varyByControlsCollection, _varyByCustom);

            HashCodeCombiner combinedHashCode = new HashCodeCombiner(_nonVaryHashCode);
            realItemCacheKey = ComputeVaryCacheKey(combinedHashCode, cachedVary);
        }

        // Compute the correct expiration, sliding or absolute
        DateTime utcExpirationTime;
        TimeSpan slidingExpiration;
        if (_useSlidingExpiration) {
            utcExpirationTime = Cache.NoAbsoluteExpiration;
            slidingExpiration = _utcExpirationTime - DateTime.UtcNow;
        }
        else {
            utcExpirationTime = _utcExpirationTime;
            slidingExpiration = Cache.NoSlidingExpiration;
        }
        
        try {
            OutputCache.InsertFragment(_cacheKey, cachedVary,
                                       realItemCacheKey, _cacheEntry,
                                       cacheDep /*dependencies*/,
                                       utcExpirationTime, slidingExpiration,
                                       _provider);
        }
        catch {
            if (cacheDep != null) {
                cacheDep.Dispose();
            }
            throw;
        }
    }
 private static ControlCachedVary UtcAdd(string key, ControlCachedVary cachedVary)
 {
     return (ControlCachedVary) HttpRuntime.CacheInternal.UtcAdd(key, cachedVary, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
 }
 internal static void InsertFragment(string cachedVaryKey, ControlCachedVary cachedVary, string fragmentKey, PartialCachingCacheEntry fragment, CacheDependency dependencies, DateTime absExp, TimeSpan slidingExp, string providerName)
 {
     OutputCacheProvider fragmentProvider = GetFragmentProvider(providerName);
     bool flag = fragmentProvider != null;
     if (flag)
     {
         bool flag2 = (slidingExp == Cache.NoSlidingExpiration) && ((dependencies == null) || dependencies.IsFileDependency());
         if (flag && !flag2)
         {
             throw new ProviderException(System.Web.SR.GetString("Provider_does_not_support_policy_for_fragments", new object[] { providerName }));
         }
     }
     if (cachedVary != null)
     {
         ControlCachedVary vary;
         if (!flag)
         {
             vary = UtcAdd(cachedVaryKey, cachedVary);
         }
         else
         {
             vary = (ControlCachedVary) fragmentProvider.Add(cachedVaryKey, cachedVary, Cache.NoAbsoluteExpiration);
         }
         if (vary != null)
         {
             if (!cachedVary.Equals(vary))
             {
                 if (!flag)
                 {
                     HttpRuntime.CacheInternal.UtcInsert(cachedVaryKey, cachedVary);
                 }
                 else
                 {
                     fragmentProvider.Set(cachedVaryKey, cachedVary, Cache.NoAbsoluteExpiration);
                 }
             }
             else
             {
                 cachedVary = vary;
             }
         }
         if (!flag)
         {
             AddCacheKeyToDependencies(ref dependencies, cachedVaryKey);
         }
         fragment._cachedVaryId = cachedVary.CachedVaryId;
     }
     if (!flag)
     {
         HttpRuntime.CacheInternal.UtcInsert(fragmentKey, fragment, dependencies, absExp, slidingExp, CacheItemPriority.Normal, null);
     }
     else
     {
         string key = null;
         if (dependencies != null)
         {
             key = "aD" + dependencies.GetUniqueID();
             fragment._dependenciesKey = key;
             fragment._dependencies = dependencies.GetFileDependencies();
         }
         fragmentProvider.Set(fragmentKey, fragment, absExp);
         if ((dependencies != null) && (HttpRuntime.CacheInternal.UtcAdd(key, new DependencyCacheEntry(fragmentKey, null, fragmentProvider.Name), dependencies, absExp, Cache.NoSlidingExpiration, CacheItemPriority.Normal, s_dependencyRemovedCallbackForFragment) != null))
         {
             dependencies.Dispose();
         }
     }
 }
        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);
        }
        protected internal override void Render(HtmlTextWriter output)
        {
            CacheDependency dependency = null;

            if (this._outputString != null)
            {
                output.Write(this._outputString);
                this.RegisterValidationEvents();
            }
            else if (this._cachingDisabled || !RuntimeConfig.GetAppConfig().OutputCache.EnableFragmentCache)
            {
                this._cachedCtrl.RenderControl(output);
            }
            else
            {
                string   str;
                DateTime noAbsoluteExpiration;
                TimeSpan noSlidingExpiration;
                if (this._sqlDependency != null)
                {
                    dependency = SqlCacheDependency.CreateOutputCacheDependency(this._sqlDependency);
                }
                this._cacheEntry.CssStyleString = this.GetCssStyleRenderString(output.GetType());
                StringWriter   tw      = new StringWriter();
                HtmlTextWriter writer  = Page.CreateHtmlTextWriterFromType(tw, output.GetType());
                TextWriter     writer3 = this.Context.Response.SwitchWriter(tw);
                try
                {
                    this.Page.PushCachingControl(this);
                    this._cachedCtrl.RenderControl(writer);
                    this.Page.PopCachingControl();
                }
                finally
                {
                    this.Context.Response.SwitchWriter(writer3);
                }
                this._cacheEntry.OutputString = tw.ToString();
                output.Write(this._cacheEntry.OutputString);
                CacheDependency dependencies = this._cacheDependency;
                if (dependency != null)
                {
                    if (dependencies == null)
                    {
                        dependencies = dependency;
                    }
                    else
                    {
                        AggregateCacheDependency dependency3 = new AggregateCacheDependency();
                        dependency3.Add(new CacheDependency[] { dependencies });
                        dependency3.Add(new CacheDependency[] { dependency });
                        dependencies = dependency3;
                    }
                }
                ControlCachedVary cachedVary = null;
                if (((this._varyByParamsCollection == null) && (this._varyByControlsCollection == null)) && (this._varyByCustom == null))
                {
                    str = this._cacheKey;
                }
                else
                {
                    string[] varyByParams = null;
                    if (this._varyByParamsCollection != null)
                    {
                        varyByParams = this._varyByParamsCollection.GetParams();
                    }
                    cachedVary = new ControlCachedVary(varyByParams, this._varyByControlsCollection, this._varyByCustom);
                    HashCodeCombiner combinedHashCode = new HashCodeCombiner(this._nonVaryHashCode);
                    str = this.ComputeVaryCacheKey(combinedHashCode, cachedVary);
                }
                if (this._useSlidingExpiration)
                {
                    noAbsoluteExpiration = Cache.NoAbsoluteExpiration;
                    noSlidingExpiration  = (TimeSpan)(this._utcExpirationTime - DateTime.UtcNow);
                }
                else
                {
                    noAbsoluteExpiration = this._utcExpirationTime;
                    noSlidingExpiration  = Cache.NoSlidingExpiration;
                }
                try
                {
                    OutputCache.InsertFragment(this._cacheKey, cachedVary, str, this._cacheEntry, dependencies, noAbsoluteExpiration, noSlidingExpiration, this._provider);
                }
                catch
                {
                    if (dependencies != null)
                    {
                        dependencies.Dispose();
                    }
                    throw;
                }
            }
        }
        internal override void InitRecursive(Control namingContainer)
        {
            HashCodeCombiner combinedHashCode = new HashCodeCombiner();

            this._cacheKey        = this.ComputeNonVaryCacheKey(combinedHashCode);
            this._nonVaryHashCode = combinedHashCode.CombinedHash;
            PartialCachingCacheEntry entry = null;
            object fragment = OutputCache.GetFragment(this._cacheKey, this._provider);

            if (fragment != null)
            {
                ControlCachedVary cachedVary = fragment as ControlCachedVary;
                if (cachedVary != null)
                {
                    string key = this.ComputeVaryCacheKey(combinedHashCode, cachedVary);
                    entry = (PartialCachingCacheEntry)OutputCache.GetFragment(key, this._provider);
                    if ((entry != null) && (entry._cachedVaryId != cachedVary.CachedVaryId))
                    {
                        entry = null;
                        OutputCache.RemoveFragment(key, this._provider);
                    }
                }
                else
                {
                    entry = (PartialCachingCacheEntry)fragment;
                }
            }
            if (entry == null)
            {
                this._cacheEntry = new PartialCachingCacheEntry();
                this._cachedCtrl = this.CreateCachedControl();
                this.Controls.Add(this._cachedCtrl);
                this.Page.PushCachingControl(this);
                base.InitRecursive(namingContainer);
                this.Page.PopCachingControl();
            }
            else
            {
                this._outputString   = entry.OutputString;
                this._cssStyleString = entry.CssStyleString;
                if (entry.RegisteredClientCalls != null)
                {
                    foreach (RegisterCallData data in entry.RegisteredClientCalls)
                    {
                        switch (data.Type)
                        {
                        case ClientAPIRegisterType.WebFormsScript:
                            this.Page.RegisterWebFormsScript();
                            break;

                        case ClientAPIRegisterType.PostBackScript:
                            this.Page.RegisterPostBackScript();
                            break;

                        case ClientAPIRegisterType.FocusScript:
                            this.Page.RegisterFocusScript();
                            break;

                        case ClientAPIRegisterType.ClientScriptBlocks:
                        case ClientAPIRegisterType.ClientScriptBlocksWithoutTags:
                        case ClientAPIRegisterType.ClientStartupScripts:
                        case ClientAPIRegisterType.ClientStartupScriptsWithoutTags:
                            this.Page.ClientScript.RegisterScriptBlock(data.Key, data.StringParam2, data.Type);
                            break;

                        case ClientAPIRegisterType.OnSubmitStatement:
                            this.Page.ClientScript.RegisterOnSubmitStatementInternal(data.Key, data.StringParam2);
                            break;

                        case ClientAPIRegisterType.ArrayDeclaration:
                            this.Page.ClientScript.RegisterArrayDeclaration(data.StringParam1, data.StringParam2);
                            break;

                        case ClientAPIRegisterType.HiddenField:
                            this.Page.ClientScript.RegisterHiddenField(data.StringParam1, data.StringParam2);
                            break;

                        case ClientAPIRegisterType.ExpandoAttribute:
                            this.Page.ClientScript.RegisterExpandoAttribute(data.StringParam1, data.StringParam2, data.StringParam3, false);
                            break;

                        case ClientAPIRegisterType.EventValidation:
                            if (this._registeredCallDataForEventValidation == null)
                            {
                                this._registeredCallDataForEventValidation = new ArrayList();
                            }
                            this._registeredCallDataForEventValidation.Add(data);
                            break;
                        }
                    }
                }
                base.InitRecursive(namingContainer);
            }
        }
 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);
 }
 protected internal override void Render(HtmlTextWriter output)
 {
     CacheDependency dependency = null;
     if (this._outputString != null)
     {
         output.Write(this._outputString);
         this.RegisterValidationEvents();
     }
     else if (this._cachingDisabled || !RuntimeConfig.GetAppConfig().OutputCache.EnableFragmentCache)
     {
         this._cachedCtrl.RenderControl(output);
     }
     else
     {
         string str;
         DateTime noAbsoluteExpiration;
         TimeSpan noSlidingExpiration;
         if (this._sqlDependency != null)
         {
             dependency = SqlCacheDependency.CreateOutputCacheDependency(this._sqlDependency);
         }
         this._cacheEntry.CssStyleString = this.GetCssStyleRenderString(output.GetType());
         StringWriter tw = new StringWriter();
         HtmlTextWriter writer = Page.CreateHtmlTextWriterFromType(tw, output.GetType());
         TextWriter writer3 = this.Context.Response.SwitchWriter(tw);
         try
         {
             this.Page.PushCachingControl(this);
             this._cachedCtrl.RenderControl(writer);
             this.Page.PopCachingControl();
         }
         finally
         {
             this.Context.Response.SwitchWriter(writer3);
         }
         this._cacheEntry.OutputString = tw.ToString();
         output.Write(this._cacheEntry.OutputString);
         CacheDependency dependencies = this._cacheDependency;
         if (dependency != null)
         {
             if (dependencies == null)
             {
                 dependencies = dependency;
             }
             else
             {
                 AggregateCacheDependency dependency3 = new AggregateCacheDependency();
                 dependency3.Add(new CacheDependency[] { dependencies });
                 dependency3.Add(new CacheDependency[] { dependency });
                 dependencies = dependency3;
             }
         }
         ControlCachedVary cachedVary = null;
         if (((this._varyByParamsCollection == null) && (this._varyByControlsCollection == null)) && (this._varyByCustom == null))
         {
             str = this._cacheKey;
         }
         else
         {
             string[] varyByParams = null;
             if (this._varyByParamsCollection != null)
             {
                 varyByParams = this._varyByParamsCollection.GetParams();
             }
             cachedVary = new ControlCachedVary(varyByParams, this._varyByControlsCollection, this._varyByCustom);
             HashCodeCombiner combinedHashCode = new HashCodeCombiner(this._nonVaryHashCode);
             str = this.ComputeVaryCacheKey(combinedHashCode, cachedVary);
         }
         if (this._useSlidingExpiration)
         {
             noAbsoluteExpiration = Cache.NoAbsoluteExpiration;
             noSlidingExpiration = (TimeSpan) (this._utcExpirationTime - DateTime.UtcNow);
         }
         else
         {
             noAbsoluteExpiration = this._utcExpirationTime;
             noSlidingExpiration = Cache.NoSlidingExpiration;
         }
         try
         {
             OutputCache.InsertFragment(this._cacheKey, cachedVary, str, this._cacheEntry, dependencies, noAbsoluteExpiration, noSlidingExpiration, this._provider);
         }
         catch
         {
             if (dependencies != null)
             {
                 dependencies.Dispose();
             }
             throw;
         }
     }
 }