static CacheSettings() { outputCacheSettings = WebConfigurationManager.GetWebApplicationSection("system.web/caching/outputCacheSettings") as OutputCacheSettingsSection; if (outputCacheSettings != null) { cdnCacheSettings = outputCacheSettings.OutputCacheProfiles["Home_CDN"]; } }
public PipelineHandler(IContentPipeline pipeline) { _pipeline = pipeline; var settings = WebConfigurationManager.GetWebApplicationSection( "system.web/caching/outputCacheSettings") as OutputCacheSettingsSection; _cacheProfile = settings.OutputCacheProfiles[CacheProfileName] ?? CreateDefaultCacheProfile(); }
public void Set(OutputCacheProfile user) { OutputCacheProfile existing = Get(user.Name); if (existing == null) { Add(user); } else { int index = BaseIndexOf(existing); RemoveAt(index); BaseAdd(index, user); } }
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation) { if (this.CacheProfile == null) { this.CacheProfile = new OutputCacheProfile("temp"); this.CacheProfile.Duration = this.Duration; this.CacheProfile.NoStore = this.NoStore; this.CacheProfile.SqlDependency = this.SqlDependency; this.CacheProfile.Location = this.Location; this.CacheProfile.VaryByCustom = this.VaryByCustom; this.CacheProfile.VaryByHeader = this.VaryByHeader; this.CacheProfile.VaryByParam = this.VaryByParam; } dispatchOperation.ParameterInspectors.Add(new CachingParameterInspector(this.CacheProfile)); }
public CachingParameterInspector(string cacheProfileName) { if (string.IsNullOrEmpty(cacheProfileName)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.CacheProfileNameNullOrEmpty)); } OutputCacheSettingsSection cacheSettings = AspNetEnvironment.Current.UnsafeGetConfigurationSection("system.web/caching/outputCacheSettings") as OutputCacheSettingsSection; if (cacheSettings == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.CacheProfileNotConfigured, cacheProfileName))); } this.cacheProfile = cacheSettings.OutputCacheProfiles[cacheProfileName]; if (this.cacheProfile == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.CacheProfileNotConfigured, cacheProfileName))); } // Validate the cacheProfile if (this.cacheProfile.Location != OutputCacheLocation.None) { // Duration must be set; Duration default value is -1 if (this.cacheProfile.Duration == -1) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.CacheProfileValueMissing, this.cacheProfile.Name, "Duration"))); } if (this.cacheProfile.VaryByParam == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.CacheProfileValueMissing, this.cacheProfile.Name, "VaryByParam"))); } } if (string.Equals(this.cacheProfile.SqlDependency, "CommandNotification", StringComparison.OrdinalIgnoreCase)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR2.CommandNotificationSqlDependencyNotSupported)); } if (!string.IsNullOrEmpty(this.cacheProfile.SqlDependency)) { ParseSqlDependencyString(cacheProfile.SqlDependency); } }
public static void Main(string[] args) { // <Snippet1> // Get the Web application configuration. System.Configuration.Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("/aspnetTest"); // Get the section. string configPath = "system.web/caching/outputCacheSettings"; System.Web.Configuration.OutputCacheSettingsSection outputCacheSettings = (System.Web.Configuration.OutputCacheSettingsSection)webConfig.GetSection( configPath); // Get the profile collection. System.Web.Configuration.OutputCacheProfileCollection outputCacheProfiles = outputCacheSettings.OutputCacheProfiles; // </Snippet1> // <Snippet2> // Execute the Add method. System.Web.Configuration.OutputCacheProfile outputCacheProfile0 = new System.Web.Configuration.OutputCacheProfile("MyCacheProfile"); outputCacheProfile0.Location = System.Web.UI.OutputCacheLocation.Any; outputCacheProfile0.NoStore = false; outputCacheProfiles.Add(outputCacheProfile0); // Update if not locked. if (!outputCacheSettings.IsReadOnly()) { webConfig.Save(); } // </Snippet2> // <Snippet3> // Execute the Clear method. outputCacheProfiles.Clear(); // </Snippet3> // <Snippet4> // Get the profile with the specified index. System.Web.Configuration.OutputCacheProfile outputCacheProfile2 = outputCacheProfiles[0]; // </Snippet4> // <Snippet5> // Get the profile with the specified name. System.Web.Configuration.OutputCacheProfile outputCacheProfile3 = outputCacheProfiles["MyCacheProfile"]; // </Snippet5> // <Snippet6> // Get the key with the specified index. string theKey = outputCacheProfiles.GetKey(0).ToString(); // </Snippet6> // <Snippet7> // Remove the output profile with the specified index. outputCacheProfiles.RemoveAt(0); // </Snippet7> // <Snippet8> // Remove the output profile with the specified name. outputCacheProfiles.Remove("MyCacheProfile"); // </Snippet8> // <Snippet9> // Get the keys. object [] keys = outputCacheProfiles.AllKeys; // </Snippet9> // <Snippet10> // Execute the Set method. System.Web.Configuration.OutputCacheProfile outputCacheProfile = new System.Web.Configuration.OutputCacheProfile("MyCacheProfile"); outputCacheProfile.Location = System.Web.UI.OutputCacheLocation.Any; outputCacheProfile.NoStore = false; outputCacheProfiles.Set(outputCacheProfile); // Update if not locked. if (!outputCacheSettings.IsReadOnly()) { webConfig.Save(); } // </Snippet10> // <Snippet11> // Get the profile with the specified name. System.Web.Configuration.OutputCacheProfile outputCacheProfile4 = outputCacheProfiles.Get("MyCacheProfile"); // </Snippet11> // <Snippet12> // Get thge profile with the specified index. System.Web.Configuration.OutputCacheProfile outputCacheProfile5 = outputCacheProfiles.Get(0); // </Snippet12> }
public void Add(OutputCacheProfile name) { BaseAdd(name); }
public void Set(OutputCacheProfile user) { BaseAdd(user, false); }
public void Set (OutputCacheProfile user) { OutputCacheProfile existing = Get (user.Name); if (existing == null) { Add (user); } else { int index = BaseIndexOf (existing); RemoveAt (index); BaseAdd (index, user); } }
public void Set(OutputCacheProfile user) { }
public void Add(OutputCacheProfile name) { }
private void SetOutputCacheProfile(string cacheProfileName) { if (_outputCacheProfile != null && _outputCacheProfile.Name.ToLower() == cacheProfileName.ToLower()) return; if (CacheSettingsSection == null) throw new Exception("<outputCacheSettings> has not been found in Web.config. Reveiw Web.config caching section: system.web//caching//outputCacheSettings."); OutputCacheProfileCollection cacheProfileCollection = CacheSettingsSection.OutputCacheProfiles; if (cacheProfileCollection.AllKeys.Contains(cacheProfileName)) { _outputCacheProfile = cacheProfileCollection[cacheProfileName]; if (this.Duration == 0) this.Duration = _outputCacheProfile.Duration; if (this.ClientTimeSpan == 0) this.ClientTimeSpan = _outputCacheProfile.Duration; if (!_disabled.HasValue) this.Disabled = !_outputCacheProfile.Enabled; } else { throw new Exception(string.Format("No OutputCacheProfile has been found in Web.config with the name of '{0}'. Reveiw Web.config caching section: system.web//caching//outputCacheSettings.", cacheProfileName)); } }
public CachingParameterInspector(OutputCacheProfile cacheProfile) { this.cacheProfile = cacheProfile; }
public void Add (OutputCacheProfile name) { BaseAdd (name); }
public void Validate(OperationDescription operationDescription) { if (!ServiceHostingEnvironment.AspNetCompatibilityEnabled) { throw new NotSupportedException("WebCacheAttribute is supported only in AspNetCompatibility mode."); } if (operationDescription.Behaviors.Find<WebGetAttribute>() == null) { throw new InvalidOperationException("The WebCacheAttribute can only be used with GET operations."); } if (!string.IsNullOrEmpty(this.CacheProfileName)) { OutputCacheProfile cacheProfile = null; OutputCacheSettingsSection cacheSettings = (OutputCacheSettingsSection)WebConfigurationManager.GetSection("system.web/caching/outputCacheSettings"); if (cacheSettings == null) { throw new InvalidOperationException(String.Format("Cache profile with name '{0}' is not configured.", this.CacheProfileName)); } cacheProfile = cacheSettings.OutputCacheProfiles[this.CacheProfileName]; if (cacheProfile == null) { throw new InvalidOperationException(String.Format("Cache profile with name '{0}' is not configured.", this.CacheProfileName)); } if (!cacheProfile.Enabled) { throw new InvalidOperationException(String.Format("Cache profile with name '{0}' is disabled.", this.CacheProfileName)); } this.CacheProfile = cacheProfile; } if (string.Equals(this.SqlDependency, "CommandNotification", StringComparison.OrdinalIgnoreCase)) { throw new NotSupportedException("CommandNotification is not supported as a valid sql dependency currently"); } // validate that the dependency has been properly configured in sql if (!string.IsNullOrEmpty(this.SqlDependency)) { foreach (SqlCacheDependency dependency in CachingParameterInspector.CreateSqlDependencies(this.SqlDependency)) { dependency.Dispose(); } } }
public static void Main() { // <Snippet1> // Get the Web application configuration. System.Configuration.Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("/aspnetTest"); // Get the section. string configPath = "system.web/caching/outputCacheSettings"; System.Web.Configuration.OutputCacheSettingsSection outputCacheSettings = (System.Web.Configuration.OutputCacheSettingsSection)webConfig.GetSection( configPath); // Get the profile at zero index. System.Web.Configuration.OutputCacheProfile outputCacheProfile = outputCacheSettings.OutputCacheProfiles[0]; // </Snippet1> // <Snippet2> // Get the current VaryByHeader. String varyByHeaderValue = outputCacheProfile.VaryByHeader; // Set the VaryByHeader. outputCacheProfile.VaryByHeader = string.Empty; // </Snippet2> // <Snippet3> // Get the current VaryByControl. String varyByControlValue = outputCacheProfile.VaryByControl; // Set the VaryByControl. outputCacheProfile.VaryByControl = string.Empty; // </Snippet3> // <Snippet4> // Get the current NoStore. Boolean noStoreValue = outputCacheProfile.NoStore; // Set the NoStore. outputCacheProfile.NoStore = false; // </Snippet4> // <Snippet5> // Get the current Location. System.Web.UI.OutputCacheLocation locationValue = outputCacheProfile.Location; // Set the Location property to null. outputCacheProfile.Location = System.Web.UI.OutputCacheLocation.Server; // </Snippet5> // <Snippet7> // Get the current SqlDependency. String sqlDependencyValue = outputCacheProfile.SqlDependency; // Set the SqlDependency. outputCacheProfile.SqlDependency = string.Empty; // </Snippet7> // <Snippet8> // Get the current VaryByParam. String varyByParamValue = outputCacheProfile.VaryByParam; // Set the VaryByParam. outputCacheProfile.VaryByParam = string.Empty; // </Snippet8> // <Snippet9> // Get the current VaryByCustom. String varyByCustomValue = outputCacheProfile.VaryByCustom; // Set the VaryByCustom. outputCacheProfile.VaryByCustom = string.Empty; // </Snippet9> // <Snippet10> // Get the current Duration. Int32 durationValue = outputCacheProfile.Duration; // Set the Duration property to 0. outputCacheProfile.Duration = 0; // </Snippet10> // <Snippet11> // Get the current Name. String nameValue = outputCacheProfile.Name; // Set the Name. outputCacheProfile.Name = string.Empty; // </Snippet11> // <Snippet12> // Get the current Enabled. Boolean enabledValue = outputCacheProfile.Enabled; // Set the Enabled. outputCacheProfile.Enabled = false; // </Snippet12> }