protected ActionResult CacheableView(string viewName, Query.Query query, Func<ModelCollection> modelAccessor, Action<OutputCacheParameters> changeSettings) { if (query.IsCacheable) { var settings = new OutputCacheParameters { Duration = query.CacheDuration, VaryByParam = null, VaryByContentEncoding = null, VaryByControl = null, VaryByCustom = null, VaryByHeader = null }; changeSettings(settings); return new CacheableViewResult { ViewName = viewName, ViewData = ViewData, TempData = TempData, ModelAccessor = modelAccessor, CacheSettings = settings }; } return View(viewName, modelAccessor()); }
public OutputCachedPage(OutputCacheParameters cacheSettings) { if (cacheSettings == null) { throw new ArgumentNullException("cacheSettings"); } ID = Guid.NewGuid().ToString(); m_cacheSettings = cacheSettings; }
/// <summary> /// http://support.microsoft.com/kb/316431 /// This method is trying to solve the problem of downloading files in IE through secure access protocol (https) /// </summary> /// <param name="cacheSettings"></param> protected override void InitOutputCache(System.Web.UI.OutputCacheParameters cacheSettings) { if (Request.Browser.Browser.ToLower() == "ie") { cacheSettings.Location = System.Web.UI.OutputCacheLocation.Client; cacheSettings.Duration = 0; cacheSettings.VaryByParam = "*"; } base.InitOutputCache(cacheSettings); }
public void InitialValues () { OutputCacheParameters o = new OutputCacheParameters (); Assert.IsNull (o.CacheProfile, "CacheProfile"); Assert.IsTrue (o.Duration == 0, "Duration"); Assert.IsTrue (o.Enabled, "Enabled"); Assert.IsTrue (o.Location == OutputCacheLocation.Any, "OutputCacheLocation"); Assert.IsFalse (o.NoStore, "NoStore"); Assert.IsNull (o.SqlDependency, "SqlDependency"); Assert.IsNull (o.VaryByControl, "VaryByControl"); Assert.IsNull (o.VaryByCustom, "VaryByCustom"); Assert.IsNull (o.VaryByHeader, "VaryByHeader"); Assert.IsNull (o.VaryByParam, "VaryByParam"); }
public virtual OutputCacheParameters GetOutputCacheParameters() { OutputCacheParameters parameters = new OutputCacheParameters(); parameters.CacheProfile = cacheProfile; parameters.Duration = duration; if (context.CurrentPage != null && context.CurrentPage.Expires.HasValue) { DateTime expires = context.CurrentPage.Expires.Value; if (expires > N2.Utility.CurrentTime() && expires < N2.Utility.CurrentTime().AddSeconds(parameters.Duration)) { parameters.Duration = (int)expires.Subtract(N2.Utility.CurrentTime()).TotalSeconds; } } parameters.Enabled = enabled; parameters.Location = OutputCacheLocation.Server; //parameters.NoStore = NoStore; //parameters.SqlDependency = SqlDependency; //parameters.VaryByContentEncoding = VaryByContentEncoding; //parameters.VaryByControl = VaryByControl; //parameters.VaryByCustom = VaryByCustom; //parameters.VaryByHeader = VaryByHeader; parameters.VaryByParam = varyByParam; return parameters; }
protected internal virtual new void InitOutputCache (OutputCacheParameters cacheSettings) { Contract.Requires (cacheSettings != null); Contract.Requires (this.Response.Cache != null); }
internal override void ProcessDirective(string directiveName, IDictionary directive) { if (StringUtil.EqualsIgnoreCase(directiveName, "outputcache")) { // Ignore the OutputCache directive in design mode (VSWhidbey 470314) if (FInDesigner) return; if (_outputCacheSettings == null) { _outputCacheSettings = new OutputCacheParameters(); } // Make sure the outputcache directive was not already specified if (_outputCacheDirective != null) { throw new HttpException( SR.GetString(SR.Only_one_directive_allowed, directiveName)); } ProcessOutputCacheDirective(directiveName, directive); _outputCacheDirective = directive; } else if (StringUtil.EqualsIgnoreCase(directiveName, "reference")) { // Ignore the OutputCache directive in design mode (VSWhidbey 517783) if (FInDesigner) { return; } // Even though this only makes sense for compiled pages, Sharepoint needs us to // ignore instead of throw when the page in non-compiled. // For historical reasons, the virtual path can be specified by 3 different attributes: // virtualpath, page and control. They all do the same, and virtualpath is the recommended // one (the other two are deprecated). // Make sure that no more than one is specified. VirtualPath virtualPath = Util.GetAndRemoveVirtualPathAttribute(directive, "virtualpath"); bool enforcePage = false; bool enforceControl = false; VirtualPath tmp = Util.GetAndRemoveVirtualPathAttribute(directive, "page"); if (tmp != null) { if (virtualPath != null) { ProcessError(SR.GetString(SR.Invalid_reference_directive)); return; } virtualPath = tmp; enforcePage = true; } tmp = Util.GetAndRemoveVirtualPathAttribute(directive, "control"); if (tmp != null) { if (virtualPath != null) { ProcessError(SR.GetString(SR.Invalid_reference_directive)); return; } virtualPath = tmp; enforceControl = true; } // If we didn't get a virtual path, fail if (virtualPath == null) { ProcessError(SR.GetString(SR.Invalid_reference_directive)); return; } Type t = GetReferencedType(virtualPath); if (t == null) { ProcessError(SR.GetString(SR.Invalid_reference_directive_attrib, virtualPath)); } // If the 'page' attribute was used, make sure it's indeed a Page if (enforcePage && !typeof(Page).IsAssignableFrom(t)) { ProcessError(SR.GetString(SR.Invalid_reference_directive_attrib, virtualPath)); } // If the 'control' attribute was used, make sure it's indeed a UserControl if (enforceControl && !typeof(UserControl).IsAssignableFrom(t)) { ProcessError(SR.GetString(SR.Invalid_reference_directive_attrib, virtualPath)); } // If there are some attributes left, fail Util.CheckUnknownDirectiveAttributes(directiveName, directive); } else { base.ProcessDirective(directiveName, directive); } }
protected internal virtual new void InitOutputCache(OutputCacheParameters cacheSettings) { }
public OutputCachedPage(OutputCacheParameters cacheSettings) { this.ID = Guid.NewGuid().ToString(); this._cacheSettings = cacheSettings; }
public CachedPage(OutputCacheParameters cacheSettings) { ID = Guid.NewGuid().ToString(); CacheSettings = cacheSettings; }
public IPackageContainer EnableHttpCaching(int cacheDuration) { var cacheParams = new OutputCacheParameters() { Duration = cacheDuration, VaryByParam = PackageContainer.VersionQueryParam }; return this.EnableHttpCaching(new PageBasedHttpCacheHandler(this.debugState, cacheParams)); }
static OutputCacheParameters getCacheParams() { OutputCacheParameters cacheParams; if (cacheProfileExists(CACHE_PROFILE_NAME)) { cacheParams = new OutputCacheParameters { CacheProfile = CACHE_PROFILE_NAME }; } else // default { cacheParams = new OutputCacheParameters { Duration = 86400, // 1 day Enabled = true, Location = OutputCacheLocation.Any, VaryByParam = "*" }; } return cacheParams; }
protected virtual void InitOutputCache(int duration, string varyByContentEncoding, string varyByHeader, string varyByCustom, OutputCacheLocation location, string varyByParam) { if (!this._isCrossPagePostBack) { OutputCacheParameters cacheSettings = new OutputCacheParameters { Duration = duration, VaryByContentEncoding = varyByContentEncoding, VaryByHeader = varyByHeader, VaryByCustom = varyByCustom, Location = location, VaryByParam = varyByParam }; this.InitOutputCache(cacheSettings); } }
protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings) { if (!this._isCrossPagePostBack) { OutputCacheProfile profile = null; HttpCachePolicy cache = this.Response.Cache; OutputCacheLocation any = ~OutputCacheLocation.Any; int seconds = 0; string varyByContentEncoding = null; string varyByHeader = null; string varyByCustom = null; string varyByParam = null; string sqlDependency = null; string varyByControl = null; bool noStore = false; RuntimeConfig appConfig = RuntimeConfig.GetAppConfig(); if (appConfig.OutputCache.EnableOutputCache) { HttpCacheability @public; if ((cacheSettings.CacheProfile != null) && (cacheSettings.CacheProfile.Length != 0)) { profile = appConfig.OutputCacheSettings.OutputCacheProfiles[cacheSettings.CacheProfile]; if (profile == null) { throw new HttpException(System.Web.SR.GetString("CacheProfile_Not_Found", new object[] { cacheSettings.CacheProfile })); } if (!profile.Enabled) { return; } } if (profile != null) { seconds = profile.Duration; varyByContentEncoding = profile.VaryByContentEncoding; varyByHeader = profile.VaryByHeader; varyByCustom = profile.VaryByCustom; varyByParam = profile.VaryByParam; sqlDependency = profile.SqlDependency; noStore = profile.NoStore; varyByControl = profile.VaryByControl; any = profile.Location; if (string.IsNullOrEmpty(varyByContentEncoding)) { varyByContentEncoding = null; } if (string.IsNullOrEmpty(varyByHeader)) { varyByHeader = null; } if (string.IsNullOrEmpty(varyByCustom)) { varyByCustom = null; } if (string.IsNullOrEmpty(varyByParam)) { varyByParam = null; } if (string.IsNullOrEmpty(varyByControl)) { varyByControl = null; } if (System.Web.Util.StringUtil.EqualsIgnoreCase(varyByParam, "none")) { varyByParam = null; } if (System.Web.Util.StringUtil.EqualsIgnoreCase(varyByControl, "none")) { varyByControl = null; } } if (cacheSettings.IsParameterSet(OutputCacheParameter.Duration)) { seconds = cacheSettings.Duration; } if (cacheSettings.IsParameterSet(OutputCacheParameter.VaryByContentEncoding)) { varyByContentEncoding = cacheSettings.VaryByContentEncoding; } if (cacheSettings.IsParameterSet(OutputCacheParameter.VaryByHeader)) { varyByHeader = cacheSettings.VaryByHeader; } if (cacheSettings.IsParameterSet(OutputCacheParameter.VaryByCustom)) { varyByCustom = cacheSettings.VaryByCustom; } if (cacheSettings.IsParameterSet(OutputCacheParameter.VaryByControl)) { varyByControl = cacheSettings.VaryByControl; } if (cacheSettings.IsParameterSet(OutputCacheParameter.VaryByParam)) { varyByParam = cacheSettings.VaryByParam; } if (cacheSettings.IsParameterSet(OutputCacheParameter.SqlDependency)) { sqlDependency = cacheSettings.SqlDependency; } if (cacheSettings.IsParameterSet(OutputCacheParameter.NoStore)) { noStore = cacheSettings.NoStore; } if (cacheSettings.IsParameterSet(OutputCacheParameter.Location)) { any = cacheSettings.Location; } if (any == ~OutputCacheLocation.Any) { any = OutputCacheLocation.Any; } if ((any != OutputCacheLocation.None) && ((profile == null) || profile.Enabled)) { if (((profile == null) || (profile.Duration == -1)) && !cacheSettings.IsParameterSet(OutputCacheParameter.Duration)) { throw new HttpException(System.Web.SR.GetString("Missing_output_cache_attr", new object[] { "duration" })); } if (((profile == null) || ((profile.VaryByParam == null) && (profile.VaryByControl == null))) && (!cacheSettings.IsParameterSet(OutputCacheParameter.VaryByParam) && !cacheSettings.IsParameterSet(OutputCacheParameter.VaryByControl))) { throw new HttpException(System.Web.SR.GetString("Missing_output_cache_attr", new object[] { "varyByParam" })); } } if (noStore) { this.Response.Cache.SetNoStore(); } switch (any) { case OutputCacheLocation.Any: @public = HttpCacheability.Public; break; case OutputCacheLocation.Client: @public = HttpCacheability.Private; break; case OutputCacheLocation.Downstream: @public = HttpCacheability.Public; cache.SetNoServerCaching(); break; case OutputCacheLocation.Server: @public = HttpCacheability.Server; break; case OutputCacheLocation.None: @public = HttpCacheability.NoCache; break; case OutputCacheLocation.ServerAndClient: @public = HttpCacheability.ServerAndPrivate; break; default: throw new ArgumentOutOfRangeException("cacheSettings", System.Web.SR.GetString("Invalid_cache_settings_location")); } cache.SetCacheability(@public); if (any != OutputCacheLocation.None) { cache.SetExpires(this.Context.Timestamp.AddSeconds((double) seconds)); cache.SetMaxAge(new TimeSpan(0, 0, seconds)); cache.SetValidUntilExpires(true); cache.SetLastModified(this.Context.Timestamp); if (any != OutputCacheLocation.Client) { if (varyByContentEncoding != null) { foreach (string str7 in varyByContentEncoding.Split(s_varySeparator)) { cache.VaryByContentEncodings[str7.Trim()] = true; } } if (varyByHeader != null) { foreach (string str8 in varyByHeader.Split(s_varySeparator)) { cache.VaryByHeaders[str8.Trim()] = true; } } if (this.PageAdapter != null) { StringCollection cacheVaryByHeaders = this.PageAdapter.CacheVaryByHeaders; if (cacheVaryByHeaders != null) { foreach (string str9 in cacheVaryByHeaders) { cache.VaryByHeaders[str9] = true; } } } if (any != OutputCacheLocation.Downstream) { if (varyByCustom != null) { cache.SetVaryByCustom(varyByCustom); } if ((string.IsNullOrEmpty(varyByParam) && string.IsNullOrEmpty(varyByControl)) && ((this.PageAdapter == null) || (this.PageAdapter.CacheVaryByParams == null))) { cache.VaryByParams.IgnoreParams = true; } else { if (!string.IsNullOrEmpty(varyByParam)) { foreach (string str10 in varyByParam.Split(s_varySeparator)) { cache.VaryByParams[str10.Trim()] = true; } } if (!string.IsNullOrEmpty(varyByControl)) { foreach (string str11 in varyByControl.Split(s_varySeparator)) { cache.VaryByParams[str11.Trim()] = true; } } if (this.PageAdapter != null) { IList cacheVaryByParams = this.PageAdapter.CacheVaryByParams; if (cacheVaryByParams != null) { foreach (string str12 in cacheVaryByParams) { cache.VaryByParams[str12] = true; } } } } if (!string.IsNullOrEmpty(sqlDependency)) { this.Response.AddCacheDependency(new CacheDependency[] { SqlCacheDependency.CreateOutputCacheDependency(sqlDependency) }); } } } } } } }
public PageBasedHttpCacheHandler(IDebugState debugState, OutputCacheParameters cacheParams) { this.debugState = debugState; this.cacheParams = cacheParams; }
/// <summary> /// Initializes a new instance of the <see cref="OutputCacheAttribute"/> class. /// </summary> public OutputCacheAttribute() { CacheSettings = new OutputCacheParameters(); VaryByParam = "none"; }
internal BuildResultNoCompilePage(Type baseType, TemplateParser parser) : base(baseType, parser) { PageParser pageParser = (PageParser) parser; // // Keep track of relevant info from the parser // _traceEnabled = pageParser.TraceEnabled; _traceMode = pageParser.TraceMode; if (pageParser.OutputCacheParameters != null) { _outputCacheData = pageParser.OutputCacheParameters; // If we're not supposed to cache it, clear out the field if (_outputCacheData.Duration == 0 || _outputCacheData.Location == OutputCacheLocation.None) { _outputCacheData = null; } else { // Since we're going to be output caching, remember all the dependencies _fileDependencies = new string[pageParser.SourceDependencies.Count]; int i = 0; foreach (string dependency in pageParser.SourceDependencies) { _fileDependencies[i++] = dependency; } Debug.Assert(i == pageParser.SourceDependencies.Count); } } _validateRequest = pageParser.ValidateRequest; _stylesheetTheme = pageParser.StyleSheetTheme; }
protected internal virtual new void InitOutputCache(OutputCacheParameters cacheSettings) { Contract.Requires(cacheSettings != null); Contract.Requires(this.Response.Cache != null); }
public new void InitOutputCache (OutputCacheParameters cacheSettings) { base.InitOutputCache (cacheSettings); }
protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings) { if (cacheSettings.Enabled) { InitOutputCache(cacheSettings.Duration, cacheSettings.VaryByContentEncoding, cacheSettings.VaryByHeader, cacheSettings.VaryByCustom, cacheSettings.Location, cacheSettings.VaryByParam); HttpResponse response = Response; HttpCachePolicy cache = response != null ? response.Cache : null; if (cache != null && cacheSettings.NoStore) cache.SetNoStore (); } }
public virtual OutputCacheParameters GetOutputCacheParameters() { OutputCacheParameters parameters = new OutputCacheParameters(); parameters.CacheProfile = cacheProfile; parameters.Duration = duration; if (context.CurrentPage != null && context.CurrentPage.Expires.HasValue) { DateTime expires = context.CurrentPage.Expires.Value; if (expires > N2.Utility.CurrentTime() && expires < N2.Utility.CurrentTime().AddSeconds(parameters.Duration)) { parameters.Duration = (int)expires.Subtract(N2.Utility.CurrentTime()).TotalSeconds; } } parameters.Enabled = Enabled; parameters.Location = OutputCacheLocation.Server; if (!string.IsNullOrEmpty(varyByHeader)) parameters.VaryByHeader = varyByHeader; if (!string.IsNullOrEmpty(varyByCustom)) parameters.VaryByCustom = varyByCustom; parameters.VaryByParam = varyByParam; return parameters; }
public OutputCachedPage(OutputCacheParameters cacheSettings) { // Tracing requires Page IDs to be unique. ID = Guid.NewGuid().ToString(); _cacheSettings = cacheSettings; }
internal override void ProcessDirective(string directiveName, IDictionary directive) { if (StringUtil.EqualsIgnoreCase(directiveName, "outputcache")) { // Ignore the OutputCache directive in design mode (VSWhidbey 470314) if (FInDesigner) { return; } if (_outputCacheSettings == null) { _outputCacheSettings = new OutputCacheParameters(); } // Make sure the outputcache directive was not already specified if (_outputCacheDirective != null) { throw new HttpException( SR.GetString(SR.Only_one_directive_allowed, directiveName)); } ProcessOutputCacheDirective(directiveName, directive); _outputCacheDirective = directive; } else if (StringUtil.EqualsIgnoreCase(directiveName, "reference")) { // Ignore the OutputCache directive in design mode (VSWhidbey 517783) if (FInDesigner) { return; } // Even though this only makes sense for compiled pages, Sharepoint needs us to // ignore instead of throw when the page in non-compiled. // For historical reasons, the virtual path can be specified by 3 different attributes: // virtualpath, page and control. They all do the same, and virtualpath is the recommended // one (the other two are deprecated). // Make sure that no more than one is specified. VirtualPath virtualPath = Util.GetAndRemoveVirtualPathAttribute(directive, "virtualpath"); bool enforcePage = false; bool enforceControl = false; VirtualPath tmp = Util.GetAndRemoveVirtualPathAttribute(directive, "page"); if (tmp != null) { if (virtualPath != null) { ProcessError(SR.GetString(SR.Invalid_reference_directive)); return; } virtualPath = tmp; enforcePage = true; } tmp = Util.GetAndRemoveVirtualPathAttribute(directive, "control"); if (tmp != null) { if (virtualPath != null) { ProcessError(SR.GetString(SR.Invalid_reference_directive)); return; } virtualPath = tmp; enforceControl = true; } // If we didn't get a virtual path, fail if (virtualPath == null) { ProcessError(SR.GetString(SR.Invalid_reference_directive)); return; } Type t = GetReferencedType(virtualPath); if (t == null) { ProcessError(SR.GetString(SR.Invalid_reference_directive_attrib, virtualPath)); } // If the 'page' attribute was used, make sure it's indeed a Page if (enforcePage && !typeof(Page).IsAssignableFrom(t)) { ProcessError(SR.GetString(SR.Invalid_reference_directive_attrib, virtualPath)); } // If the 'control' attribute was used, make sure it's indeed a UserControl if (enforceControl && !typeof(UserControl).IsAssignableFrom(t)) { ProcessError(SR.GetString(SR.Invalid_reference_directive_attrib, virtualPath)); } // If there are some attributes left, fail Util.CheckUnknownDirectiveAttributes(directiveName, directive); } else { base.ProcessDirective(directiveName, directive); } }