internal override void LoadRecursive() { // If we're in a cache hit, don't do anything special if (_outputString != null) { base.LoadRecursive(); return; } // Make sure the Page knows about us while the control's OnLoad is called Page.PushCachingControl(this); base.LoadRecursive(); Page.PopCachingControl(); }
internal override void PreRenderRecursiveInternal() { // If we're in a cache hit, don't do anything special if (_outputString != null) { base.PreRenderRecursiveInternal(); // register the cached styles on the Header control. if (_cssStyleString != null && Page.Header != null) { Page.Header.RegisterCssStyleString(_cssStyleString); } return; } // Make sure the Page knows about us while the control's OnPreRender is called Page.PushCachingControl(this); base.PreRenderRecursiveInternal(); Page.PopCachingControl(); }
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); } }
/// <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; } }